问题
After migrating to v1.10 sorting by hidden column stopped working.
Fiddler Example v1.10 http://jsfiddle.net/0rstgd4f/
var dataTableInfo = $("#dataTable1").DataTable(
{
"initComplete": function(settings, json)
{
settings.aoColumns[0].iDataSort = 1;
}
});
<table id="dataTable1">
<thead>
<tr>
<th>
Column1
</th>
<th style="display:none;">
Column2
</th>
<th>
Column3
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
1
</td>
<td style="display:none;">
1
</td>
<td>
a
</td>
</tr>
<tr>
<td>
2
</td>
<td style="display:none;">
2
</td>
<td>
b
</td>
</tr>
<tr>
<td>
3
</td>
<td style="display:none;">
1
</td>
<td>
c
</td>
</tr>
</tbody>
</table>
v.1.8.2 http://jsfiddle.net/rzzrbwb0/
Columns should be sorted as: 1 3 2
or 2 1 3
I tried to use new definition for initComplete as columns(), column() and so on but it did not work.
Any ideas and suggestions are welcome.
回答1:
I don't think initComlete
is the correct place to change DataTables behavior, at least for 1.10. From the manual:
DataTables stores the configuration and data for each table in a settings object. The structure of this object is considered to be private in terms of the DataTables API and reading or writing to the values in the object is not supported. The property names and values contained within the object can, will and do change between versions!
If you're using DataTables 1.10, it should be defined using columns.orderData or columnDefs.orderData, see the example below:
var dataTableInfo = $("#dataTable1").DataTable({
"columnDefs": [
{ "orderData": 1, "targets": [ 0 ] }
]
});
See this JSFiddle for demonstration.
来源:https://stackoverflow.com/questions/30538878/datatables-v1-10-sorting-by-hidden-column