Sorting Value for cell in a nested javascript object data source

Sorting Value for cell in a nested javascript object data source

Martin@hecoMartin@heco Posts: 12Questions: 5Answers: 0

The jquery datatables plugin v1.10 is able to enhance an already existing html-table and is able to read a special data-order tag for providing a different sorting value, as seen here:

        <tr>
            <td>System Architect</td>
            <td data-order="1303686000">Mon 25th Apr 11</td>
            <td data-order="320800">$320,800/y</td>
        </tr>

This works fine - we are trying to achieve the same with a nested javascript object as source, like so

{
    "jobDescription":"System Architect",
    "startDate": {
        "display": "Mon 25th Apr 11",
        "sort": 1303686000
    },
    "salary": {
        "display": "$320,800/y",
        "sort": 320800
    }
},

However, it does not seem to work this way. Is there an already existing way to provide the sorting value or do we have to implement our own?

Thank you in advance.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    That will work, have a look at the orthogonal data section of the manual and also the columns.data property documentation.

    Allan

  • Martin@hecoMartin@heco Posts: 12Questions: 5Answers: 0

    Ah, it does work, if the type is manually set to "num". From the orthogonal data page, I was under the impression, that the type-parameter is a render option. Maybe this should be added to the manual.

    For future reference, here is an example

    Thanks for the help, Allan!

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    You want to avoid setting the type if you can and just let DataTables detect it automatically. The issue was that the display property was being used for type detection in your example - you want to tell it to use sort - updated example.

    Allan

This discussion has been closed.