Changing the column settings dynamically in code

Changing the column settings dynamically in code

karthi_bkarthi_b Posts: 3Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I want to modify the settings for columns dynamically in the code and would like to referesh the table based on the new settings.

For example,
[code]
var oTable = jQuery('#example').dataTable({'iDisplayLength' : 20});
var oSettings = oTable.fnSettings();
oSettings.aoColumns[1]['sWidth']='20%'; //modify the width of second column
oTable.fnDraw();
[/code]

In the above example, I want to make the second column width as 20% in the code. I tried to set the column attribute and redraw the table. But the changes are not reflected. I am not sure where I am making mistake. Please let me know whether this is possible.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    No mistake - it is just not a supported option to change configuration properties on-the-fly like this. You could try calling fnAdjustColumnSizing rather than fnDraw, which might work, but it wouldn't really be by design! To be 100% confident that what calls you make, you'd need to go through the DataTables source and see what the internal calls you would nee to make (fnAdjustColumnSizing is a good place to start!).

    Allan
This discussion has been closed.