remove a class from a row?

remove a class from a row?

loukinglouking Posts: 259Questions: 52Answers: 0

Sorry I don't have a simple test case, but I think this may be a simple question.

I see from https://datatables.net/manual/ajax#Optional-parameters how to add a class to a row using DT_RowClass.

Is there any way to remove the class I added later?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Yes, use rows().nodes(). See the example in the docs.

    Kevin

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2023

    I could probably make that work. But I was wondering if there is anything the server can send to tell datatables to remove the class on a given row.

    Ultimately what I'm trying to do is color a row based on some data within the row.

  • loukinglouking Posts: 259Questions: 52Answers: 0

    I was able to use DT_RowAttr to get what I am looking for:

    on server

            if row['is_confirmed']:
                row['DT_RowAttr'] = {'is_confirmed': True}
            else:
                row['DT_RowAttr'] = {'is_confirmed': False}
    

    on client css

      table.dataTable tbody tr[is_confirmed="true"]
      {
          background-color: #99FF99;  /*green*/
      }
    
  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    Another option is to use createdRow or rowCallback, if the data can change, to apply styling to the row or cells in a row based on a condiftion. See this example.

    Kevin

Sign In or Register to comment.