columnDefs not working with bStateSave = ture

columnDefs not working with bStateSave = ture

alamnaryabalamnaryab Posts: 4Questions: 3Answers: 0
edited July 2021 in DataTables 1.10

Hi friends
I have datetable with columnDefs to hide few coulmns by default, it is working fine
but when I make bStateSave:true then no coulmns are hidden

       var table = $('.dt').DataTable({
        orderCellsTop: true,
        fixedHeader: true,
        "order": [],
        "pageLength": 10,

    // "bStateSave":true,
        // "stateSaveParams": function (settings, data) {
        //     data.start = 0;
        //     data.search.search = "";
        //     $.each(data.columns,function(i,v){
        //         //prevent column level searching 
        //         v.search.search = "";
        //     });
        // },

        dom:"<'row'<'col-sm-3'l><'col-sm-6 text-center'B><'col-sm-3'f>>" +
                "<'row'<'col-sm-12'tr>>" +
                "<'row'<'col-sm-5'i><'col-sm-7'p>>",
        "columnDefs": [
                                  { "visible": false, "targets": 1 }, 
                                  { "visible": false, "targets": 2 }, 
                                  { "visible": false, "targets": 3 }, 
                                  { "visible": false, "targets": 4 }, 
                        ],  

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    It seems to be working as expected here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    Answer ✓

    Sounds like the state was saved with the columns visible. You can use stateLoadParams to removed the columns from being loaded so the columnDefs are applied.

    Kevin

Sign In or Register to comment.