table.column(colIdx).data().sort(), to sort by columnDefs:data:sort?
table.column(colIdx).data().sort(), to sort by columnDefs:data:sort?
Summary
I want to access the column().data() in the sort order defined for that column.
my table parameters includes defining a hidden sort column, so that when sorting target column "5", it is sorted by the value in column "10". - this works fine for sorting inside the the table.
inTable= $('#tasks').DataTable( {
"ajax": "data",
"columnDefs": [
{"targets": 5,
"data" : {
"_" : "5",
"sort": "10"
}
}]
})
The issue is that I am trying to create a column filter and using the below javascript to fill in the select options. They fill in the right values, but I would like the sorting to be by column 10.
inTable.columns( '.select-filter' ).eq( 0 ).each( function ( colIdx ) {
var select = $('<select />');
...
inTable
.column( colIdx )
.sort() //***How do we get this to sort according to columnDefs?***
.data()
.unique()
.each( function ( d ) {
select.append( $('<option value="'+d+'">'+d+'</option>') );
} );
})
I would like the .column(colIdx).data() sorted according to the {"data": "sort" : "10"} parameter defined in the table init.
Any ideas? the .column(colIdx).sort() will only sort the same as how the table is sorted, instead of sorted by the sort column "10"
Answers
example code (look at select for salary column) is here:
http://www.datatables.net/examples/api/multi_filter_select.html
Note, the salary column filter select is incorrectly sorted.
I found an extremely ugly work around. Resort the table before creating each select. This seems like a lot processing. Any better ideas?
Use:
:-)
The
selector-modifier
option can be very useful for this kind of thing.Allan