How to preserve/pass-through html th attributes to DataTable initialization?

How to preserve/pass-through html th attributes to DataTable initialization?

tdaytday Posts: 6Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
This is a great progressive enhancement tool - congratulations!

I am saving the column sort settings (on the server) of each column (the class "sorting_asc" or "sorting_desc") from the element. When recreating the table, I re-apply the class attribute using a handlebar template. The problem I encounter is during DataTable initialization which sets other defaults. The initialization seems to override the th class attribute that is in the html DOM.

Here is the table header:
[code]


Test Data
Time
Rank
Coefficient
Forecast


[/code]

Here is the initialization code I use:
[code]
$forecastContainer.find('table.test-data').dataTable( {
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
//"aaSorting": [[ 2, "asc" ]], //sorting configuration set in html template by specifying class attribute on each th
"aoColumns": [
/* Test Data */ null,
/* Time Shift */ null,
/* Forecast Date */ null,
/* Confidence Interval */ null,
/* Slider */ {
"bSearchable": false,
"bSortable": false },
/* Forecast */ {
"bSearchable": false,
"bSortable": false }
]
} );
[/code]

How can I honor the existing th class attribute when initializing the table?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    There is no option for that at the moment built into DataTables. You would need to use jQuery / DOM methods to get the class and calculate the default sort to apply to the table.

    Or possibly bStateSave might be of some use.

    Allan
  • tdaytday Posts: 6Questions: 0Answers: 0
    Thank you Allan,
    This confirms my search through the documentation.
    Kind Regards
This discussion has been closed.