Enable disable fixed column in DataTable using a button

不羁的心 提交于 2020-01-17 02:58:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!