Presenting and sorting data in different ways
Presenting and sorting data in different ways
samstarling
Posts: 1Questions: 0Answers: 0
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!
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!
This discussion has been closed.
Replies
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.
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