ArtiGrid
conditional colors in cells and rows
Conditional Colors for Cells and Rows
This example shows how ArtiGrid applies conditional styling to individual cells or entire rows using dynamic rules based on field values.
1. Apply Color to a Specific Cell (CellColor)
You can highlight a single cell when a condition is met. The rule compares the field value and applies a CSS style string.
$grid->CellColor('officeCode', '==', 4, 'background:red;color:white');
In this case, when officeCode equals 4, the cell background becomes red and the text becomes white.
2. Apply Style to an Entire Row (RowColor)
You can also style the full row using structured style rules defined as an array.
$grid->RowColor('paymentDate', '==', '2004-11-14', [
'background' => '#8DED79',
'color' => '#000',
'font-weight' => 'bold'
]);
If the condition is met, the entire row is styled using the provided properties instead of a single string. This allows cleaner and more flexible styling control.
3. Rendering the Grid
$grid->table('payments');
echo $grid->render();
After defining the rules, calling render() generates the table with all conditional styles applied dynamically on the frontend.
Summary
CellColor applies styles to individual cells, while RowColor applies styles to full rows.
RowColor now supports structured style arrays, allowing multiple CSS properties without needing !important or string concatenation.
<?php
$grid = new ArtiGrid();
$grid->CellColor('checkNumber', '==', 'NG94694', 'background:green;color:white;');
$grid->CellColor('paymentDate', '==', '2004-03-10', 'background:red;color:white;');
$grid->RowColor('paymentDate', '==', '2004-11-14', [
'background' => '#8DED79',
'color' => '#000',
'font-weight' => 'bold'
]);
$grid->table('payments');
echo $grid->render();
?>