Change appearance grid cell

andremuller, Mon Jul 01 2024, 02:22PM

I need to change the color of certain elements in the grid, depending on a condition. One situation is that I need to keep track of dates that are expired. How can I do that?
Re: Change appearance grid cell
VictorUlloa, Tue Jul 02 2024, 10:13AM

[EDITED]

You can use the onEachRow event for the grid, and replace the value for the element with a DIV using it to change background/foregroud or other properties:

(versionInstalada - versionVigente - nombreSoftware: columns names from my sample grid)


function dbgrid_1_onEachRow($app, &$row)
{
// Change cell background based on condition
if ($row->versionInstalada < $row->versionVigente) {
$row->nombreSoftware = '< div style="background:#FFE2B8;color:>#E51C23">'.$row->nombreSoftware.'< /div>';
}
}

Hope this helps

Please note that I inserted an extra space in the opening and closing DIV tags, because the forum was interpreting it as part of the HTML of the page.
So for the code to work in your app, just remove the extra space in "< div" and "< /div>".

Regards
Re: Change appearance grid cell
andremuller, Tue Jul 02 2024, 12:06PM

So easy! Thank you.
Re: Change appearance grid cell
bkafecadm, Wed Jul 17 2024, 07:37PM

Just an additional comment, you can also use other tags and css classes to do so, for example '

' . $row->columnName . '

'
Re: Change appearance grid cell
VictorUlloa, Fri Jul 26 2024, 11:47PM

Revisiting this issue I noted that your last response is not shown complete... can you repost the sample, please? Thank you vey much...
Re: Change appearance grid cell
bkafecadm, Sat Jul 27 2024, 03:36PM

Apologies, it goes like this

< P class="text-primary"> $row->columnName </ P >
Re: Change appearance grid cell
bkafecadm, Sat Jul 27 2024, 03:38PM

Apologies, it goes like this

< P class="text-primary"> $row->columnName < / P >