Are stateSave and columnDefs incompatible?

Are stateSave and columnDefs incompatible?

russellrussell Posts: 3Questions: 2Answers: 0

I seem to only be able to allow either stateSave or columnDefs (to hide a column) to work. I can comment the code out for one or the other and everything works, but as soon as I uncomment both, the column is no longer hidden:

    $(document).ready(function () {
        $('#FeedbackTable').dataTable
            (
                {
                    "stateSave": true,                  // Save state, so when users return to this page, they see what was displayed previously.

                    "columnDefs": [
                        {
                            "targets": [ 6 ],           // Make Column 7 (counting starts at zero)
                            "visible": false,           // Not Visible
                            "searchable": true          // But Searchable
                        }
                    ]
                    ,
                    "order": [[1, "asc"]],              // Default sort by first column, ascending
                    "pagingType": "full_numbers",       // Sets paging to include First, Previous, numbers, Next, and Last.
                    "iDisplayLength": 10                // Number of items per page
                }
            );
        $('#FeedbackTable_length').css("display", "none");
    });

I've commented out other things also, trying to simplify the problem; I provided all code in case it's something else.

Thanks,

Russell

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,036Questions: 1Answers: 10,169 Site admin
    Answer ✓

    The column visibility is saved from before, so if the column was previously visible it will still be visible due to the state saving. So it is not that they are incompatible, but rather interacting.

    Use the code above (i.e. hide the column) in a browser you haven't used before for the page - or in Chrome's Incognito mode and you should see it work.

    Allan

  • russellrussell Posts: 3Questions: 2Answers: 0

    Ahh... and the default is two hours, so it's been working the whole time, I just couldn't tell! :-)

    Awesome.

    Thank you Allan.

This discussion has been closed.