custom sorting issue

custom sorting issue

sonicbugsonicbug Posts: 26Questions: 0Answers: 0
edited May 2011 in General
Hi Allan:

I am trying to utilize the priority sort code with slight modifications made, however, I get the following error:

oSort[iDataType +
[Break On This Error] aoData[b]._aData[iDataSort] line 4000


[code]
priority= function (a) {
a = a.toLowerCase();
if (a == "january") { return 1; }
else if (a == "february") { return 2; }
else if (a == "march") { return 3; }
else if (a == "april") { return 4; }
else if (a == "may") { return 5; }
else if (a == "june") { return 6; }
else if (a == "july") { return 7; }
else if (a == "august") { return 8; }
else if (a == "september") { return 9; }
else if (a == "october") { return 10; }
else if (a == "november") { return 11; }
else if (a == "december") { return 12; }
return 13;
console.log("priority function ran");
}


jQuery.fn.dataTableExt.oSort['month-asc'] = function (a, b) {
var x = priority(a);
var y = priority(b);

return ((x < y) ? -1 : ((x > y) ? 1 : 0));

};
jQuery.fn.dataTableExt.oSort['month-desc'] = function (a, b) {
var x = priority(a);
var y = priority(b);

return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

[/code]

I am looking to see if you can shed some light on this.

Thanks again,

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    That looks fair enough to me - so I'm not sure what is wrong with it. Perhaps you can show us a working example, or at least your initialisation code?

    Allan
  • sonicbugsonicbug Posts: 26Questions: 0Answers: 0
    Hi Allan:

    Here is my initialization code:

    [code]

    /* generate a table - dataTable */
    $('#flood_reports').html('');
    var oTable = $('#daily_flood_reports_table').dataTable({
    "iDisplayLength": 9999,
    //"iCookieDuration": 0,
    "oLanguage": {
    "sSearch": "Search Flood Reports by date:",
    "sLengthMenu": 'Show ' +
    'most recent' +
    '10' +
    '25' +
    '50' +
    '100' +
    'All' +
    ' entries'
    },
    "sPaginationType": "full_numbers",
    "aaSorting": [[0, "desc", 0], [1, "desc", 0], [2, "desc", 0]],
    "aaData": csv_flood_reports,
    "aoColumns": [
    { "sTitle": "Year", "sType": "month-desc" }, // "sType": "date"
    {"sTitle": "Month" },
    { "sTitle": "Day" },
    { "sTitle": "English" },
    { "sTitle": "Français" }
    ]
    });

    [/code]

    Thanks in advance.
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Change your sType to be just "month" for the first column - not "month-desc" which it the type plus the sorting direction.

    Allan
  • sonicbugsonicbug Posts: 26Questions: 0Answers: 0
    Thanks again Allan, it worked like a charm!
This discussion has been closed.