Incorrect sort type detection with function mDataProp

Incorrect sort type detection with function mDataProp

DanMorinDanMorin Posts: 28Questions: 0Answers: 0
edited February 2012 in Bug reports
I noticed when mDataProp is a function, the sort type detection is incorrect, using the 'display' data, rather than the 'sort' data.

For instance, my table displays transactions. The first column displays the transaction date, however I want to sort by the transaction ID from the database to make sure all the transactions are displayed in consecutive order in case two transactions occurred within the same minute. As a result, my raw data rgData[0] contains the database ID representing the transaction, and I want to use this ID as my sort key.

When I use the following code, the sorting becomes incorrect because _fnSort() already autodected the sDataType as a 'date' instead of a 'numeric'.

_fnSort() in jquery.dataTables.js:
[code]
for ( k=0, kLen=aDataSort.length ; k

Replies

  • allanallan Posts: 64,756Questions: 1Answers: 10,716 Site admin
    > I noticed when mDataProp is a function, the sort type detection is incorrect, using the 'display' data, rather than the 'sort' data.

    Actually - it should be using "type" rather than either "display" or "sort" ( http://datatables.net/docs/DataTables/1.9.0/DataTable.defaults.columns.html#mDataProp ) :-).

    So in the above code you would want to have:

    [code]
    if ((eType === 'sort' || eType === 'type') && idSort != undefined)

    [/code]

    Allan
  • DanMorinDanMorin Posts: 28Questions: 0Answers: 0
    Thanks for the tip, it is working without the need for "sType": "numeric".

    I can confirm the sDataType === 'numeric' at line ~3830 in jquery.dataTables.js.

    I thought that the code for 'type' was the following:

    [code]if (eType === 'type')
    return 'numeric';
    [/code]
  • allanallan Posts: 64,756Questions: 1Answers: 10,716 Site admin
    That would set the sType to numeric certainly, but your mDataProp function is all about the data that is used. Because numeric data will be automatically detected by DataTables when numeric data is given for a column there should be no need to ever set that - the thing to be aware of is returning numeric data from your mDataProp function and then everything else should fall into place (as does the filtering etc).

    Allan
This discussion has been closed.