Presenting and sorting data in different ways

Presenting and sorting data in different ways

samstarlingsamstarling Posts: 1Questions: 0Answers: 0
edited March 2014 in General
Hello,

I'm just getting started with DataTables, so forgive me if I've missed something! I've got a cell in my table that contains unformatted price information. For example:

[code]1394.1[/code]

I'm formatting it like this:

[code]
$('.table-data').dataTable({
"aoColumnDefs": [
{
"mRender": function (data, type, full) {
return "£" + parseFloat(data).toFixed(2);
},
"aTargets": ["tbl-price"]
}
]
});
[/code]

However, when I sort on that column, I get "£101, £1001, £203, £2040" - so the column is being sorted on the string I'm generating. How can I get the column to sort correctly (101, 203, 1001 etc.) whilst still having the nicely formatted number?

Thanks!

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    I've done something similar but with names instead of numbers.
    http://datatables.net/release-datatables/examples/basic_init/hidden_columns.html
    I put the last name (for sorting) in the "hidden" column, with the full name in a visible column. There may be other ways but this suits me.
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    You need to use the `type` argument to determine what kind of data DataTables is asking for. For the `sort` and `type` types, use the plain number.

    Check out the DataTables 1.10 manual page on orthogonal data, which will be of some help: http://next.datatables.net/manual/orthogonal-data

    Allan
This discussion has been closed.