Retrieve 'data-order' tags via API

Retrieve 'data-order' tags via API

pclaarpclaar Posts: 8Questions: 4Answers: 0

I'm trying to retrieve an array of data-order values in a DataTable column via the API.

The data for each cell is structured like this:

<td data-order="16.719">105<br />(16.7%)</td>

When I call
var data = myTable.api().column(colNumber).data();

The value for this cell is: "105<br />(16.7%)"

I'm trying to retrieve the data-order attribute (16.719).

Any way to do this via the API?

Pete

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    There actually isn't an API for getting a specific type of data (not sure why I haven't thought of that before...). The data() APIs will always return the raw data.

    For the moment what you need to do is loop over the nodes for the cells and retrieve their data-order attribute.

    Going forward, it certainly makes sense to be able to retrieve the orthogonal data types via the API and it something I will look at adding in future. Thanks for bring it up!

    Regards,
    Allan

  • pclaarpclaar Posts: 8Questions: 4Answers: 0

    Thanks Allan, appreciate the response! I'll just pull the attributes for now.

    Cheers,

    Pete

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I should point out that if you set the attributes (in the same way that you can pull them using cell().node() to get the element), use cell().invalidate() or row().invalidate() to have DataTables update its cached data for the row.

    Allan

This discussion has been closed.