Special sort for 1 column
Special sort for 1 column
RoyHB
Posts: 4Questions: 0Answers: 0
I've just started using DataTables - very nice and useful work.
I have a problem that I can't quite figure out the solution to.
In my table there is one column that requires some special handling when sorting. The column has a class named 'Q'.
I initialise dataTables:
[code]
$("#tableLeft").dataTable({
"aLengthMenu": [[35, 70, -1], [35, 70, "All"]],
"iDisplayLength":"35",
"aoColumnDefs": [{ "sSortDataType": "qpos", "aTargets": [ "Q" ] }]
});
[/code]
My expectation is that this will cause plugin's named qpos-asc or qpos-desc will be called as the sort callbacks when the column has the class "Q" and it's clicked.
The purpose of the special sort is to cause any entries that are not numeric or have numeric values < 1 to be sorted to the bottom of the table for an asc sort and the top of the table for a desc sort.
The qpos functions I have are:
[code]
$.fn.dataTableExt.afnSortData['qpos-asc'] = function(a,b) {
var badAssign = 9999;
if ($.isNumeric(a["queue_position"]) && a["queue_position"] > 0) { aItem = a["queue_position"]; }
else { aItem = badAssign; }
if ($.isNumeric(b["queue_position"]) && b["queue_position"] > 0) { bItem = b["queue_position"]; }
else { bItem = badAssign; }
return ((aItem < bItem) ? -1 : ((aItem > bItem) ? 1 : 0));
};
$.fn.dataTableExt.afnSortData['qpos-desc'] = function(a,b) {
var badAssign = 9999;
if ($.isNumeric(a["queue_position"]) && a["queue_position"] > 0) { aItem = a["queue_position"]; }
else { aItem = badAssign; }
if ($.isNumeric(b["queue_position"]) && b["queue_position"] > 0) { bItem = b["queue_position"]; }
else { bItem = badAssign; }
return ((aItem < bItem) ? 1 : ((aItem > bItem) ? -1 : 0));
};
[/code]
It appears that the sort functions qpos-asc and qpos-desc are never called.
I'm sure that I've made some irritating newbie error.
Help would be most appreciated
Roy
I have a problem that I can't quite figure out the solution to.
In my table there is one column that requires some special handling when sorting. The column has a class named 'Q'.
I initialise dataTables:
[code]
$("#tableLeft").dataTable({
"aLengthMenu": [[35, 70, -1], [35, 70, "All"]],
"iDisplayLength":"35",
"aoColumnDefs": [{ "sSortDataType": "qpos", "aTargets": [ "Q" ] }]
});
[/code]
My expectation is that this will cause plugin's named qpos-asc or qpos-desc will be called as the sort callbacks when the column has the class "Q" and it's clicked.
The purpose of the special sort is to cause any entries that are not numeric or have numeric values < 1 to be sorted to the bottom of the table for an asc sort and the top of the table for a desc sort.
The qpos functions I have are:
[code]
$.fn.dataTableExt.afnSortData['qpos-asc'] = function(a,b) {
var badAssign = 9999;
if ($.isNumeric(a["queue_position"]) && a["queue_position"] > 0) { aItem = a["queue_position"]; }
else { aItem = badAssign; }
if ($.isNumeric(b["queue_position"]) && b["queue_position"] > 0) { bItem = b["queue_position"]; }
else { bItem = badAssign; }
return ((aItem < bItem) ? -1 : ((aItem > bItem) ? 1 : 0));
};
$.fn.dataTableExt.afnSortData['qpos-desc'] = function(a,b) {
var badAssign = 9999;
if ($.isNumeric(a["queue_position"]) && a["queue_position"] > 0) { aItem = a["queue_position"]; }
else { aItem = badAssign; }
if ($.isNumeric(b["queue_position"]) && b["queue_position"] > 0) { bItem = b["queue_position"]; }
else { bItem = badAssign; }
return ((aItem < bItem) ? 1 : ((aItem > bItem) ? -1 : 0));
};
[/code]
It appears that the sort functions qpos-asc and qpos-desc are never called.
I'm sure that I've made some irritating newbie error.
Help would be most appreciated
Roy
This discussion has been closed.
Replies
Allan
Once I changed the methodology and fixed my bug all works well