0

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?

mpsbhat
  • 2,733
  • 12
  • 49
  • 105
  • enable or disable in what context.. they should not behave as a fixed column after disabling and vice verca ? – Ankush Jain Aug 14 '14 at 05:28
  • Myself want to enable fixed column feature in some cases. In other conditions it should be disabled using a button click. Again, it should be enabled if the user click the button again and vice versa. – mpsbhat Aug 14 '14 at 05:37
  • Please see my answer below @AnkushJain – mpsbhat Aug 16 '14 at 08:58

3 Answers3

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.

mpsbhat
  • 2,733
  • 12
  • 49
  • 105
0

I think all you can do is add or remove "sorting" class on each click

BPT
  • 36
  • 4
0

For me, it worked.

$(".DTFC_Cloned").addClass('d-none');

.DTFC_Cloned is a class datatables gives to a cloned table with fixed column data.