Highlight an entry in row if contains pattern
Highlight an entry in row if contains pattern
nitinb82
Posts: 12Questions: 3Answers: 0
Hi,
New to DataTables so please pardon if a re-post.
Is it possible to highlight an entry (either bold or different color) in a row if it contains a pattern? Eg.,
Make the 3rd entry bold if it contains a 'G'.
T/G G/G **A/G** NA A/A NA
To take it further, is it possible to make only 'G' appear in bold (and not 'A')?
T/G G/G A/**G** NA A/A NA
Thanks so much!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @nitinb82 ,
This example here will show you how to highlight cells conditionally. You'll just need to use standard JS regex magic to determine whether to highlight it.
Cheers,
Colin
Thanks, colin. I tried the following simple thing, but it does not work. Can you please tell me if there is anything wrong?
I am trying to make the entry in the 4th column bold if it is above 25.
Thanks in advance for any help.
You should be seeing a syntax error in the browser's console. You need a comma at the end of line 7 before
""order":....
.Do you have a class for bold, something like this?
Kevin
Thanks Kevin, that comma actually renders the table well. So, that part is fixed.
But, being a newbie at DataTables, I don't know where do I specify the class
bold
. Can I specify it somewhere in the block above (9 lines)?Can I directly say it as follows?
$('td', row).eq(3).addClass(font-weight:bold)
Thanks for all your help!
You can use the jQuery css() method. Something like this:
$('td', row).eq(3).css('font-weight','bold');
Kevin
It worked! This is very helpful. Thanks, Kevin!
Hi Kevin, I am struggling to create such highlighting function for multiple columns:
In the above case, it only highlights the 4th column. How can I get it to highlight both (or more) columns depending upon the two thresholds?
Thanks in advance!
The second
createdRow
you have is overwriting the first. You will need both if statements in onecreatedRow
. Something like this:Kevin
That worked! Thank you so much, Kevin!