Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a class to a th

It's easy enough to add a class to a td in a webgrid, for example:

new WebGridColumn {
    ColumnName= "Owl.Species",
    Header= "Scientific Name",
    Style= "sci-name"
}

The style tag adds the class "sci-name" to the td. How can I add a class to the th for that column without using jQuery which wouldn't be the ideal solution.

like image 408
TheLearningDev Avatar asked Nov 12 '22 23:11

TheLearningDev


1 Answers

I don't think there's a built-in way to do it. You can't even extend the WebGrid classes, as their methods aren't marked virtual. The best way I can think of is to use some CSS, nth-child to target the th element by its index.

<style type='text/css'>
    table thead tr th:nth-child(2) {
        background: yellow;
    } 
</style>

Still not ideal, but I think better than using JQuery.

like image 164
McGarnagle Avatar answered Dec 31 '22 04:12

McGarnagle