问题
Myself created a html table with fixed columns using jquery DataTable with reference to This example as,
$(document).ready(function() {
var table = $('#example').DataTable( {
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
} );
new $.fn.dataTable.FixedColumns( table, {
leftColumns: 2
} );
} );
UPDATE: Myself trying to enable/disable the fixed column using a button as given in this fiddle as,
var columnNumber = 2;
$('#ToggleColumns').click(function () {
if(columnNumber == 2)
{
columnNumber = 0;
}
else {
columnNumber = 2;
}
foo();
where the foo()
contains the columnNumber to be fixed. What is the correct syntax to toggle the column number based on the button?
回答1:
It is solved by using table.destroy();
method of datatable and initializing new options with new columnNumber.
Sample Link: http://jsfiddle.net/eqsadgez/1/
Please suggest if any better ways.
回答2:
I think all you can do is add or remove "sorting" class on each click
来源:https://stackoverflow.com/questions/25300624/enable-disable-fixed-column-in-datatable-using-a-button