Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomark1 opened this issue Jan 17, 2024 · 1 comment
Open

Comments

@thomark1
Copy link

thomark1 commented Jan 17, 2024

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.

@thomark1 thomark1 changed the title stateSave not working with Select2 using ajax as source stateSave not working with Select2 when using ajax as source Jan 17, 2024
@jarrettj
Copy link

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

@thomark1 thomark1 changed the title stateSave not working with Select2 when using ajax as source stateSave not working with Select2 when using server-side filtering Mar 14, 2024
@thomark1 thomark1 changed the title stateSave not working with Select2 when using server-side filtering stateSave not working with Select2 when using server-side ajax filtering Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants