问题
I have a responsive Datatable that also has the Show/Hide columns feature enabled. I've noticed that whenever I hide a column using the show/hide buttons, a new column will automatically appear in order to fill the width of the page.
Is there a way to disable this so that if I toggle a column to hide, another column does not try and fill its place, but the existing columns will just fit the width of the page?
A test case of my current issue can be found here: http://live.datatables.net/huruwaro/1/edit
Thanks for your time!
回答1:
Try to redraw the table after clicking the button
$('#myTable1').DataTable().clear().draw();
or
$('#myTable1').DataTable().columns.adjust().draw();
or
$('#myTable1').DataTable().columns.adjust().draw(false);
来源:https://stackoverflow.com/questions/59670605/js-datatables-toggle-show-hide-with-responsive-auto-showing-other-columns