How do I set an ID or class on the TH of a column in javascript?

How do I set an ID or class on the TH of a column in javascript?

tacman1123tacman1123 Posts: 179Questions: 41Answers: 1

I'd like to set an id or class on JUST a column header. I know I can set className on a column definition, but that's set the class on all the cells, and I just want it set on the header.

I'm trying to access the column header to dynamically change it, but having a hard time figuring out how. I can add a className, then just get it by "th .<className>", but that's awkward. I want to avoid using numeric indexes altogether.

Are there any column options that are specific to the header, besides title? There's a name, which I've set, but that doesn't render anything. So maybe there's some way to search for a column by name, get the header, and then set the contents?

Thanks.

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    I think that columns().header() should help. The first example shows removing a class but you you should be able to addClass() instead and just have it apply to the header. Note the use of to$() to get a jQuery object for this to work.

    Kevin

This discussion has been closed.