I am using the prime-ui datatable. I have to highlight certain rows if a condition is true. This condition depends on the Json data which we pass to the table.
How can we specify the condition in this case ?
$('#divInWhichTableIsRendered').puidatatable({
columns: [
{field:'f1', headerText: 'f1', sortable:true},
{field:'f2', headerText: 'f2', sortable:true},
{field:'f3', headerText: 'f3', sortable:true},
{field:'f4', headerText: 'f4', sortable:true},
{field:'f5', headerText: 'f5', sortable:true}
],
datasource: ourJson1,
});
Played around a amount of time, did come up with this 'solution'. Unfortunately it is not the exact solution you want. I'll explain the problem after the solution.
1.) We need to use the property
contentof the colum definitions.2.) Use content on every column:
3.) Write a function that takes the
rowDataand checks if this element must be highlighted or not.Problem: We can only 'highlight' the
spanwe've created. Neither thetdnor thetr. Why? Because thespangets inserted when the function returns the jQuery object. Before that, we do not have access to thetdortr. I don't know of we can add some callbacks to do it afterwards. (A hack will be a mouseover which ranges over the whole viewport and calls a function, but that's a hack imho.)Bring this all together:
Here is the fiddle