Set background color of column

Set background color of column

msand01msand01 Posts: 54Questions: 24Answers: 1

I would like to change the background color of columns that are editable, but when I do this using the classname, it also changes the background color of that column's header, which I don't want. Is there a way to highlight the td cells but not the th? This is how I currently have it:

DT column
{ "data": "UserFlag", "className": "table-cell-edit" }

CSS
.table-cell-edit{
    background-color: lightgoldenrodyellow;
}

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    See the documentation on DT styling:
    https://datatables.net/manual/styling/classes

  • msand01msand01 Posts: 54Questions: 24Answers: 1

    But if I only want to change the background color of the editable columns, which in my case is a subset of all the columns in the table. It seems like the example mentioned changes style for the entire table.

  • allanallan Posts: 62,006Questions: 1Answers: 10,165 Site admin
    Answer ✓

    The method you suggest of using columns.className and a CSS style is the correct way to do it.

    If the whole table is changing, that suggests all cells have table-cell-edit on them, or perhaps a parent element such as the table does, since the selector isn't being restricted by node name.

    Perhaps try using td.table-cell-edit? If that doesn't work, we'd need a link to the page.

    Allan

  • msand01msand01 Posts: 54Questions: 24Answers: 1

    Thank you, setting my css class as you suggested did the trick.

    td.table-cell-edit{
        background-color: lightgoldenrodyellow;
    }
    
This discussion has been closed.