vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
732 stars 285 forks source link

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

Open thomark1 opened 5 months ago

thomark1 commented 5 months ago

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.

https://github.com/vedmack/yadcf/assets/37288204/a71a0601-4929-4699-b738-131ba000c7c5

{
    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.

jarrettj commented 3 months ago

Hey, good day.

Same issue :|.

Here it works: https://yadcf-showcase.appspot.com/DOM_source_select2.html Here it does not: https://yadcf-showcase.appspot.com/DOM_Ajax_Multiple_1.10.html

In the older API it works in the example, but not the new one. Any help would be much appreciated :).

Regards, Jarrett