Manually click ColVis restore button

Manually click ColVis restore button

brockta7brockta7 Posts: 4Questions: 2Answers: 0

I have tried many methods to unhide all the hidden columns in my DataTable including:

tbl.columns().visible(true).draw();

or using a for loop like:

for(var x = 0; x < tbl.Count(); x++)
{
tbl.column(x).visible(true);
}

tbl.columns().draw();

The only way I can get the hidden columns back, is by using colvisRestore and clicking the Restore Visibility button. I'm hoping that I can use ColReorder to reorder the columns back to default, and then manually click the ColVis restore button within a JS function to reorder/unhide all columns in one click.

I've tried to use JQuery to manually click the button within the function:

$('#dt-button buttons-colvisRestore').click()

but that doesn't work for me.

Is there any way to manually click the restore visibility button in JS, so that I can run additional code alongside that logic?

Any help would be much appreciated.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    Answer ✓

    Maybe I'm missing something but this test case seems to work:
    http://live.datatables.net/miqadihe/1/edit

    It starts out with two hidden columns. I can hide others using the Column Visibility Button. Then click another button I created to "Show All". "Show All" uses table.columns().visible(true); to restore visibility to all columns.

    Kevin

  • brockta7brockta7 Posts: 4Questions: 2Answers: 0

    Kevin, I'm not sure what the deal was with my JS/CSS ColVis headers but I switched over to the ones you references in the example and it worked fine after that.

    Thank you so very much for replying and offering to help.

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    edited September 2018

    I used the Download Builder to obtain the latest versions of Datatables, Buttons and Column Visibility for that test case.

    Kevin

This discussion has been closed.