Generate TD Cell Class Based on TH Column Header

Generate TD Cell Class Based on TH Column Header

Howdy_McGeeHowdy_McGee Posts: 1Questions: 1Answers: 0

I don't have any test cases or anything to debug. I have a problem looking for a solution.

The problem is that each Datatable TD cell doesn't have any descriptive classes assigned to them, making it difficult to style in specific cases. I was wondering if there was a way I could, instead of manually assigning or defining classes, I could generate classes to assign based on the (TH) header column title or a header column attribute.

The examples I see of classes are done through colDefs which require the index of the column to which you're assigning the class. My Datatables vary in length and data, so a generated approach is preferred. Any help or points in a direction would be helpful as I'm familiar with JS, just not familiar enough with Datatables to discern how to do this properly.

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Yep, the columns.className would be the normal way of assigning a class. There are callbacks you can use too, such as createdRow where you can also assign classes (the example on the reference page is doing just that). Hopefully one of those will do the trick, but if not, please write back and say how you want those classes to look and get assigned.

    Colin

Sign In or Register to comment.