Colvis and background change for specifc column

Colvis and background change for specifc column

trongarttrongart Posts: 222Questions: 51Answers: 0

This test case uses the Buttons, Colvis and colReorder extentions:

live.datatables.net/putarafo/1/edit

There is a rowCallback which changes the background of the Age column based on a condition which originally is at index 3. When Colvis is applied and the Age column removed, this rowCallback is applied on any other column that has index 3. Is there a way to apply the background change only on column "Age"
by name or by data-column-index that stays static instead of by td:eq(3) ?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    I'd say use createdRow instead - then it does that rendering when the table is first initialised - see here .

    Colin

  • trongarttrongart Posts: 222Questions: 51Answers: 0
    edited October 2021

    @colin Thank you for your help here- this was working until I used deferRender. For some reason background change is not applied correctly with deferRender and createdRow.

    Have a look at this example with Ajax: live.datatables.net/texavogu/1/edit

    Values of >= 5000 in the Extn column are to be shaded green. Everything starts out correctly, but when you add the Office column with ColVis and then sort descending by Extn column, for some reason the Office column values start being shaded instead of Extn values.

    Is there a way to do this with deferRender?

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    I figured it out! Just need to give columns a class name and use that in createdRow.

Sign In or Register to comment.