Sort order of complex data
Sort order of complex data
Multiman
Posts: 2Questions: 1Answers: 0
I am using this method to load data and render
$('#DealPerformance').dataTable( {
"columns": [
{ "data": "id" },
{ "data": "dealInfo",
"render": function ( data, type, full, meta ) {
return createDealInfo(data);
}
}...
My data is a nested data structure
[ {id : "abc", dealInfo : {name: "BDP", amount: "20", state: "open"}}, {id : "xyz", {dealInfo : {..}}} ]
my function createDealInfo() creates a nice HTML snippet which is inserted into the table cell.
But I would like to use dealInfo.amount as the sort key for the column instead of the whole HTML snippet. Can anyone show me how to do that?
I found https://datatables.net/examples/ajax/orthogonal-data but it is not clear to me how this works when using the render prperty.
Thanks
Alex
This discussion has been closed.
Answers
I found a solution: just add a hidden span to the beginning of the HTML content my function createDealInfo() creates. In order to trick the alphanumeric sort I am also padding the number into leading zeros.
This will convert a data.dealVolume of 23000 into '00023000' so the sorting works nicely.