Setting Column filter value after page reload with stateSave

Setting Column filter value after page reload with stateSave

shussainshussain Posts: 1Questions: 1Answers: 0

I have a table with column filtering, I have a mix of select and input fields. I have set stateSave to yes so column filters are remembered after a page reload and I have noticed that the state on individual column filters is not saved between reloads/ refreshes.
So I'm using the below code to add the states back into the column filters, unfortunately it only seems to wok fro the text input not the select dropdown.

Any help would be greatly appreciated.

var state = table.state.loaded();
    if(state) {
        table.columns().every( function (colIdx) {
            var colSearch = state.columns[colIdx].search;
            if (colSearch.search) {
                var filter = colSearch.search.replace(/[\^\$]/g,'');
                $('input', this.footer()).val(filter);
                $('select', this.footer()).val(filter);
            }
        });    

        table.draw();
    }

This is how I've added the inputs to the columns

$('#performance_log tfoot th').each( function () {
        if($(this).hasClass('look')){
            $(this).html( '<input type="text" placeholder="Search..." class="table_foot_filter">' );
        }
        else if($(this).hasClass('drop')){
            $(this).html( '<select class="table_foot_filter"><option value=""></option></select>' );
        }
        else{
            $(this).html('');
        } 
    });

And the initial setup of options

var table = $("#performance_log").DataTable({
        "paging":   false,
        "searching":true, 
        "ordering": true,
        "info":     true, 
        "stateSave": true,
        "columnDefs": [
            {"orderable": false, "targets": [0]} 
          ],

    });

Answers

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin

    Perhaps you can link to a page showing the issue please? What you have there I would have expected to work.

    Allan

Sign In or Register to comment.