Setting Column Data Color on Sort

Setting Column Data Color on Sort

kraftomatickraftomatic Posts: 78Questions: 13Answers: 0

Hi All,

I've got the following table where the color is set to red initially, based on the default sort order:

http://live.datatables.net/yohuluco/12/edit

What I'm trying to do is move that color of red to whatever column is clicked on/sorted on. The current code sets red here in the rowCallback function:

$(row).find('td:eq(3)').css('color', '#ac1a2f'); // sets color for total points

What would be the cleanest way to do this?

Thank you,

Ed

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    See this example:
    http://live.datatables.net/yohuluco/13/edit

    In rowCallback you can get an instance of the Datatable API with this.api(). Next get the table order. note you can have more than one column being ordered. The example just gets the first in the array. Then use column.index() with the visible parameter to get the visible index to take in consideration the hidden column.

    All the cells will need to be reset to the default color first then apply the color to the sorted column.

    Kevin

  • kraftomatickraftomatic Posts: 78Questions: 13Answers: 0

    Brilliant, thank you Kevin.

    Ed

This discussion has been closed.