Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82610

Special sort for 1 column

$
0
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:
$("#tableLeft").dataTable({
     "aLengthMenu": [[35, 70, -1], [35, 70, "All"]],
     "iDisplayLength":"35",
     "aoColumnDefs": [{ "sSortDataType": "qpos", "aTargets": [ "Q" ] }]                    
});

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 <th> 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:
$.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));
};


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

Viewing all articles
Browse latest Browse all 82610

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>