Updating HTML5 data-* Attributes for Orthogonal Data

Updating HTML5 data-* Attributes for Orthogonal Data

VegetronVegetron Posts: 2Questions: 1Answers: 0
edited July 2014 in Free community support

Hi,

I'm using DataTables with orthogonal data for ordering some of my columns. Furthermore users can change the value of the data-order attribute of the first cell of each row by clicking on a row. This is shown in the reduced example at http://live.datatables.net/wepalov/1/edit?html,js,output.

In the reduced example a user can click on a row and the data-order attribute of the first cell in this row is changed to the value '1'. The default data-order attribute is '0'. Although the data-order attribute can be changed, it does not affect the ordering of the rows when using the first column head for sorting. The order of the rows remains unchanged.

Is there a way to update the data-* attributes at runtime (after the initialization) and take them into account for ordering and searching/filtering?

Thank you for your support.

This question has an accepted answers - jump to answer

Answers

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

    Yes indeed - set the attribute's value using jQuery of a straight setAttribute() as you are but then you need to tell DataTables about the change.

    This is done by invalidating the row or cell in question (the cell invalidation in DataTables is actually a bit of cheat at the moment, it just invalidates the whole row...). That can be done with row().invalidate() or cell().invalidate().

    The invalidation will cause DataTables to read the information from the DOM when you next call the draw() method.

    Updated example: http://live.datatables.net/wepalov/2/edit

    Allan

  • VegetronVegetron Posts: 2Questions: 1Answers: 0

    Thank you very much Allan!
    This solved my problem. Great!

This discussion has been closed.