Conditional Formatting on some of the cells in my table
Conditional Formatting on some of the cells in my table
Hello All,
I am very new to DataTables and Editor, and I am trying to find any details I can on how to perform a specific task.
I am wanting to change the background colour of certain cells within my table, based on the data that is in that cell. This is both before or after an edit, and on multiple pages of data.
I am using the .NET libraries within MVC,
I want to do something like the below (code is for example and is not intended to be correct!)
$('#tablename').on("change", function () {
if ($('#tablename').cellvalue.startsWith("P")) {
$('#tablename').addClass('pass');
}
});
Can anyone tell me the correct way to achieve this please? I only want this condition to be checked on certain cells, not all cells within the table.
Many thanks.
This question has an accepted answers - jump to answer
Answers
rowCallback
might be what you are looking for.Kevin
@kthorngren thank you! This was just what I needed. I have included the code I used below in case it helps anyone in the future.
PS : the "i" flag in /RegExp/i is optional and stands for case insensitive (so it will also return true for "Passed", "pAssEd", etc.). and the td:eq(1) should reflect the number of the field you are formatting.
Neil.