Coloring a row based on column value doesn't work
Coloring a row based on column value doesn't work
peterbelove
Posts: 27Questions: 8Answers: 0
I am trying to highlight a row based on the value of a certain column, but seems like it doesn't.
tried both #1 and #2 but doesn't work, anyone could help?
Many thanks.
createdRow: function ( row, data, dataIndex ) {
if ( data[1] == 'Accountant' ) {
$(row).addClass( 'danger' );
}
createdRow: function ( node, data ) {
if ( data.position == 'Accountant' ) {
$(node).addClass( 'danger' );
}
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You need to add
!important
to ensure the class isn't over-written - see here: http://live.datatables.net/huzoyaxi/2/editColin
Thank you very much. That solves the problem!
A separate question as following -
I also added the click&highlight function. but it doesn't overlap the existing colouring.
$('#example tbody').on( 'click', 'tr', function () {
$(this).toggleClass('selected');
});
e.g. if you click on the yellow row in below link, nothing happens.
http://live.datatables.net/kuzajico/1
is there a way to make click&highlight happen on the yellow row?
Thanks,
I see you've raised a new thread for this question too. I'll reply there later in the day.
Colin
for anyone has similar doubt, pls see
https://datatables.net/forums/discussion/comment/185491#Comment_185491
thanks Colin!