SORT COLUMN NUMBER

SORT COLUMN NUMBER

hugomeanahugomeana Posts: 18Questions: 0Answers: 0
edited February 2013 in General
Hello,

I have this code for a column:

[code]
{
"mData": "credito_restante",
"sDefaultContent": "",
"bSortable": true,
"mRender": function (val, type, row) {

var sReturn = "" + val + "";
return sReturn;
}
},
[/code]

But when I sort by this column, it sorts as a text, not as a number.
I try this:

sType: numeric

But not works, Any idea please??

Thank you!

Replies

  • hugomeanahugomeana Posts: 18Questions: 0Answers: 0
    SOLVED !

    http://stackoverflow.com/questions/11341379/datatables-sorts-strings-instead-of-numeric

    Thanks!
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Try this:

    [code]
    "mRender": function (val, type, row) {
    if ( type === 'display' ) {
    return "" + val + "";
    }
    return val;
    }
    [/code]

    i.e. for the `display` type it will use your markup, otherwise it uses the plain value (for sort, type checking and filter). See: http://datatables.net/blog/Orthogonal_data for more information.

    Allan
This discussion has been closed.