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?

3
  • enable or disable in what context.. they should not behave as a fixed column after disabling and vice verca ? Commented Aug 14, 2014 at 5: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. Commented Aug 14, 2014 at 5:37
  • Please see my answer below @AnkushJain Commented Aug 16, 2014 at 8:58

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.