Enable/Disable features after initializing the table
Enable/Disable features after initializing the table
Hello,
I have a table that has this feature "bSort": false. Later if the user clicks on "Make table sortable" the datatable should be sortable. I can't figure out a way to change bSort: true after the datatable is loaded. I looked it up online, and some are saying it is impossible. Please let me know if it can be done, or if there is an alternative to fix my problem.
PS: I am new to JQuey, Jscript, so please try to be more specific.
Many thanks in advanced.
I have a table that has this feature "bSort": false. Later if the user clicks on "Make table sortable" the datatable should be sortable. I can't figure out a way to change bSort: true after the datatable is loaded. I looked it up online, and some are saying it is impossible. Please let me know if it can be done, or if there is an alternative to fix my problem.
PS: I am new to JQuey, Jscript, so please try to be more specific.
Many thanks in advanced.
This discussion has been closed.
Replies
- reconsider why you want to have this functionality (no kidding: why would you want to offer this functionality?)
- create a new Datatable when user clicks 'Make table sortable', but this time with sorting enabled.
- write your own sort-functionality using the fnSort function and add this functionality when user clicks 'Make table sortable'.
I don't know where the table-wide sortable setting is, but here is an example of disabling sort on a certain column:
[code]
var oTable = $('#example').dataTable();
// get settings object after table is initialized
var oSettings = oTable.fnSettings();
// disable sorting on column "1"
oSettings.aoColumns[1].bSortable = false;
[/code]
[code]
var len = oTable.fnGetData(0).length;
for (var i = 0; i < len; i++) {
oSettings.aoColumns[i].bSortable = false;
}
[/code]
I don't know if this works, but it's the right idea. You'd have to play with it
The short answer is that you cannot alter initialisation options after the table has been initialised, unless there is an API available for it. You need to reinitialise the table.
Allan