ColVis Restore Column not working

ColVis Restore Column not working

itsupport@sullivancotter.comitsupport@sullivancotter.com Posts: 2Questions: 1Answers: 0

Having same issue as http://www.datatables.net/forums/discussion/7242/colvis-restore-column-not-working.
I save the setting of the ColVis in a cookie, but if I hide columns and leave the page, once I've come back to the page it loads fine with the correct columns hidden, but the RESTORE COLUMNS button no longer works. If I hide or show another column then click that button, it only toggles that column.

I tried using both colVis extension and Buttons with colVis.
I even tried using local storage as well as default cookie.

After page refresh restore seems to consider newly selected columns also in default visible list.

Answers

  • allanallan Posts: 61,435Questions: 1Answers: 10,049 Site admin

    Hi,

    Yes, what you are seeing is the expected behaviour for the code as it currently is. The restore button will get the column visibility values of the table when it is initialised (which includes the column visibility when the state is restored) so it thinks that is the original state.

    I can see how that would not be the desired behaviour, but a fix might actually be quite complicated and take some time I'm afraid, which I'm not entirely sure when I'll be able to do.

    Allan

  • harsshharssh Posts: 1Questions: 0Answers: 0

    Hi ,

    Is there any way to fix or patch this I am having the same issue

  • itsupport@sullivancotter.comitsupport@sullivancotter.com Posts: 2Questions: 1Answers: 0

    We currently implemented local-storage for state save and load and began seeing this issue .

    Is there any update on this ?

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    The way I solved this for my application was to create my own "Show/Hide All" button that then calls my own functions where I send a css selector for the columns I want to hide/show. The selector is for instances where I have permanently hidden columns.

    DataTable button config

                   {
                        text: 'Show All',
                        action: function ( e, dt, node, config ) {
                            yv.datatables.restoreTableColumnViz();
                        }
                    },
                    {
                        text: 'Hide All',
                        action: function( e, dt, node, config ) {
                            yv.datatables.hideAllColumnViz();
                        }
                    }
    

    JavaScript functions

    restoreTableColumnViz: function(selector) {
            selector = selector || '';
            var dataTable = yv.datatables.getCurrDataTableObj();
            if (!dataTable) { 
                return;
            }
            dataTable.columns(selector).visible(true);
        },
        
    hideAllColumnViz: function(selector) {
            selector = selector || ':not(.not-colvis-col)';
            var dataTable = yv.datatables.getCurrDataTableObj();
            if (!dataTable) {
                return;
            }
            dataTable.columns(selector).visible(false);
        },
    
  • allanallan Posts: 61,435Questions: 1Answers: 10,049 Site admin

    Sorry - there is no update on this issue yet. As noted above the issue is that ColVis (and Buttons - now that ColVis has been retired) doesn't see the original column visibility, therefore it can't restore that.

    What would probably be required is a button that will set the column visibility as required (columnVisibility) - that would work identically to the restore button from the end user's point of view, but it would require setting what columns you want to be visible and what hidden in the button configuration.

    Allan

This discussion has been closed.