DataTable not show filter selected option after refresh page

DataTable not show filter selected option after refresh page

tonj83tonj83 Posts: 1Questions: 0Answers: 0

Hi,
i have this problem...
I have a datatable that have as filter column selected component but when i refresh the page the filter in table is applied, but the selected option not...
Can anyone help me please?
I'm using "stateSave": true and i have no problem on text field.
this is the code...

<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#myTable').DataTable({
            initComplete: function () {
                /*this.api().columns().every(function () {*/
                this.api().columns([4, 8, 11, 12, 13]).every(function () {
                    var column = this;
                    var select = $('<select class="myselect"><option value=""></option></select>')
                        .appendTo($(column.footer()).empty())
                        .on('change', function () {
                            var val = $.fn.dataTable.util.escapeRegex(
                                $(this).val()
                            );

                            column
                                .search(val ? '^' + val + '$' : '', true, false)
                                .draw();
                        });


                    column.data().unique().sort().each(function (d, j) {
                        select.append('<option value="' + d + '">' + d + '</option>')
                    });



                });
            },
            "order": [[12], [1, "desc"]],
            /*"order": [[13, 11, 9, "desc"]],*/
            /*"ordering": false,*/
            'aoColumnDefs': [{
                'bSortable': false,
                'aTargets': [-1, -5, -6, -7, -8, -11, -12] /* 1st one, start by the right */
            }],
            "stateSave": true, 
            "stateDuration": 60 * 10, 
            "pageLength": 10
        });
    });

</script>

Thanks...

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @tonj83 ,

    Yep, stateSave , by default, will only save things it knows about - i.e. column ordering, table filtering, etc. Because that column filter is something you added to the the table, you need to instruct stateSave how to save those values, and how to retrieve them.

    This example here from this thread should help - it's saving the selected rows, you would do something similar to save the searches,

    Cheers,

    Colin

This discussion has been closed.