column.visible() & state.save()

column.visible() & state.save()

monkeyboy71monkeyboy71 Posts: 5Questions: 1Answers: 0

I have stateSave enabled on my table. And I have a JS function that enables toggling of column visibility.

But... I can't get the column visibility states to save.

I have tried manually triggering a state.save() after any column.visible() change, but that didn't do it.

How might I get a column change to save in the state settings?

Thanks for the advice.

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Doesn't calling "table.state.save();" in your toggle function take care of it?

  • monkeyboy71monkeyboy71 Posts: 5Questions: 1Answers: 0
    edited July 2015

    It does not. And I'm not sure if it's either a) not calling or b) being overwritten on table initialization on reload.

    //table load
    var table = $('.points_table').DataTable({
        stateSave: true,
        paging: true,
        ordering: true,
        order: [[ 2, 'desc']],
        responsive: {
            breakpoints: [
                { name: 'desktop', width: Infinity },
                { name: 'tablet',  width: 1024 },
                { name: 'fablet',  width: 768 },
                { name: 'phone',   width: 500 }
            ]
        },
        pagingType: 'full_numbers' 
    });
    
    // toggle function
    $('.toggle-vis').on( 'change', function (e) {
        var column = table.column( $(this).attr('data-column') );
        column.visible( ! column.visible() );
        table.state.save(); // this isn't working
    });
    
  • monkeyboy71monkeyboy71 Posts: 5Questions: 1Answers: 0

    I should note, the toggle consists of checkboxes, hences the onChange bind.

  • monkeyboy71monkeyboy71 Posts: 5Questions: 1Answers: 0

    Additionally, I tested the stateSaveCallback() to make sure the correct values were getting submitted via stateSave and the are all in there. I am not sure where stateSave writes to so I'll go track that down and check it out. Or maybe try and write out to the console what the values are on load.

  • monkeyboy71monkeyboy71 Posts: 5Questions: 1Answers: 0

    Turns out it's the responsive code. It works with my manual code OR with colVis extension IF there is no responsive code. So, debugging continues.

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    responsive: {

    Yes - that is the issue. Currently ColVis and Responsive cannot operate on the same table together as they are both trying to use the same DataTables column visibility control.

    This is something I indent to address in a future update.

    Allan

This discussion has been closed.