Sort order of complex data

Sort order of complex data

MultimanMultiman 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

Answers

  • MultimanMultiman Posts: 2Questions: 1Answers: 0

    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.

    '<span style="display:hidden">' + 
    String(1e15 + Math.round(data.dealVolume) + "").slice(8) +
    '</span>'
    

    This will convert a data.dealVolume of 23000 into '00023000' so the sorting works nicely.

This discussion has been closed.