Set table coloum background color on a condition using jquery





2.00/5 (1 vote)
Normal 0 false false false EN-US X-NONE X-NONE
There are some projects which require to high light rows which matches the filter criteria in grid view or table, but there are other requirements where we have to highlight the entire column based on the column cell text/header text.
This functionality/requirement can be handled by user when user perform a click operation on column header or hover mouse on to the column or when user loads the data he would specify the filter expression to high light a specific column header value.
This can be handled through JavaScript also which requires a complex script to be written, but with JQuery you can write the script easily.
Here in this example, column “PF” is highlighted.
Following is the Script used to highlight the column.
$(document).ready(function() {
var pfColumn = $("#Grid_CoWorking th:contains('PF')");
var index = $("#Grid_CoWorking th").index(pfColumn);
$("#Grid_CoWorking td:nth-child(" + (index + 1) + ")").css("background-color", "red");
});