aoColumnDefs: Default
aoColumnDefs: Default
On a table where all the columns except the 1st are formatted numbers, I want to make the sorting plugin 'formatted-num' the default, and make the 1st column be sorted as a string instead.
Here's my initialization code:
jQuery('#tableid-1').dataTable( {
"aaData": dataid_1,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"bFilter": true,
"bInfo": true,
"iDisplayLength": 25,
"aoColumnDefs": [{"aTargets":['_all'],"sType":'formatted-num'},
{"aTargets":[0],"sType":'string'}],
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"oLanguage": {
"sSearch": ''
},
"aaSorting": [[0, "asc"]],
"bProcessing": true,
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
return sReturn;
}
} );
Note that I might now know how many columns I might be generating when the table is initialized.
'_all' instead of acting as a default, seems to override any subsequent reference; so "aTargets":[0] seems to be ignored. (Tested under Safari). Any suggestions?
Regards.
Here's my initialization code:
jQuery('#tableid-1').dataTable( {
"aaData": dataid_1,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"bFilter": true,
"bInfo": true,
"iDisplayLength": 25,
"aoColumnDefs": [{"aTargets":['_all'],"sType":'formatted-num'},
{"aTargets":[0],"sType":'string'}],
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"oLanguage": {
"sSearch": ''
},
"aaSorting": [[0, "asc"]],
"bProcessing": true,
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
return sReturn;
}
} );
Note that I might now know how many columns I might be generating when the table is initialized.
'_all' instead of acting as a default, seems to override any subsequent reference; so "aTargets":[0] seems to be ignored. (Tested under Safari). Any suggestions?
Regards.
This discussion has been closed.
Replies
Do it the other way around and it should work fine:
[code]
"aoColumnDefs": [
{"aTargets":[0],"sType":'string'},
{"aTargets":['_all'],"sType":'formatted-num'}
],
[/code]
DataTables will give priority to the first element in the aoColumDefs array. So top priority at the top, lowest at the bottom :-)
Allan