Skip to content

stateSave not working with Select2 when using server-side ajax filtering #678

Description

@thomark1

When stateSave is enabled, the filter is set to "select2" and data are retrieved with ajax, the filter is not properly set after page reload.

chrome_yeBc3dPQEL.mp4
{
    column_number: 10,
    select_type: "select2",
    select_type_options: {
        width: '100%',
        language: "{{ config('app.locale') }}",
        placeholder: '@lang('global.choose')',
        dropdownAutoWidth: true,
        allowClear: true,
        theme: 'bootstrap-5',
        minimumInputLength: 3,
        templateSelection: formatProduct,
        templateResult: formatProduct,
        ajax: {
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            type: "POST",
            url: '/ajaxGetProductsSelect2Search',
            dataType: 'json',
            delay: 250,
            data: function (params) {
                var query = {
                    search: params.term,
                    type: 'public'
                };

                return query;
            },
            processResults: function (data) {
                var arr = []
                $.each(data, function (index, value) {
                    arr.push({
                        id: value['tw_Nazwa'],
                        text: value['tw_Nazwa'],
                        symbol: value['tw_Symbol'],
                    })
                })

                return {
                    results: arr
                };
            }
        },
    },
    style_class: 'form-control',
    filter_reset_button_text: false,
}

function formatProduct(option) {
    var symbol = option.symbol ? ' <strong>[' + option.symbol + ']' : '';
    var $ob = $('<span value='+option.text+'>' + option.text + symbol + '</span>');
    return $ob;
}

DataTables version: 1.13.8
Yadcf version: 0.9.4.beta.46

Any hints for how to get it working? Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions