Change colorof the line in Datatabel widget

14 views
Skip to first unread message

Anderson Florencio

unread,
Feb 15, 2016, 7:47:52 AM2/15/16
to ZnetDK
Hello Pascal, there is the possibility of modifying the color of a row of a Datatable widget according to a conditional clause?

Pascal Martinez

unread,
Feb 15, 2016, 4:38:01 PM2/15/16
to ZnetDK
Hello Anderson,

The ZnetDK datatable widget does not allow natively to highlight a row according to a specific criterium.

However, you can add a little JavaScript code into the view containing your datatable and so highlight a row when it matches a value in particular.

For example, into the view of the ZnetDK CRUD demo (named "democrudview.php") add the following lines of code to change the background color of the row containing the value "PN4123" in the second column.

<script>
$
(document).ready(function () {
    $
("#demo-crud-table").on('zdkdatatabledataloaded',function(){
        $
(this).find('td:nth-child(2)').each(function(){
           
if ($(this).text()==='PN4123') {
               $
(this).parent().css('background','lightgreen');
           
}
       
});
   
});
});
</script>

Tell me if it suits your needs.

Regards,

Pascal MARTINEZ

Anderson Florencio

unread,
Feb 16, 2016, 12:08:50 PM2/16/16
to ZnetDK
Yes, that's all I need, rs! Thanks!

Pascal Martinez

unread,
Feb 16, 2016, 3:34:51 PM2/16/16
to ZnetDK
OK, cool ;-)
Reply all
Reply to author
Forward
0 new messages