Custom Sorting

Custom Sorting

AshAsh Posts: 2Questions: 0Answers: 0
edited January 2011 in General
Hi,

I have a data table with a column which is combination of numeric & string. When it loads for the first time i get an error saying 'lenth is null or is not an object"

Here is the exact nature of my column......i have which holds . based on some condition i am either showing or stirng "insufficient number". when this table loads it fails on aoColumn. here is the code i am using:

[code]
tblKD = $("#tblKD").dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"bJQueryUI": true,
"bSortClasses": false,
"asStripClasses": [],
"aoColumns": [
null,
null,
{ "sSortDataType": "dom-fav", "sType": "numeric" },
null,
null,
null,
{ "bSortable": false }
],
"aaSorting": []

});

$.fn.dataTableExt.afnSortData['dom-fav'] = function(oSettings, iColumn) {
var aData = [];


$('td:eq(' + iColumn + ') ul li.liFav', oSettings.oApi._fnGetTrNodes(oSettings)).each(function() {

aData.push(LPad($(this).attr('title').replace('%', ''), 2, '0'));
});

return aData;
}
[/code]

how can i handle this situation?

Thanks
Ash

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Which part exactly is giving the length error? I don't immediately see anything obvious...

    Allan
  • AshAsh Posts: 2Questions: 0Answers: 0
    its [code]{ "sSortDataType": "dom-fav", "sType": "numeric" },[/code].

    it looks for a numeric value. If it finds a string instead of a number it fails. if i remove my string "insufficient responses" from this column & let it come out with valid interger numbers it works fine.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Can you add a check in your 'dom-fav' function to see if there is suitable information in it - and if not just return a 0. The numeric sort is expecting numeric data - so anything that isn't is going to trip it up.

    Allan
This discussion has been closed.