Get KoolPHP UI with 30% OFF!

How to change Row color while rendering the row

Jayme
Hello,
I would like to change the row background color before rendering the row when one of its columns assumes a certain value.
In the documentation exists the example below:
<?php				
	$grid = new KoolGrid("grid");
	
	class MyGridEventHandler extends GridEventHandler
	{
		function OnRowPreRender($row,$args)
		{
			$row->CssClass = "blueColor"; // Make the row in blue color.			
		}
	}
	$grid->EventHandler = new MyGridEventHandler();
?> 

I did not find how to get access to columns values using the GridRow class, though.
Best regards.
Posted Feb 15, 2017 , edited Feb 15, 2017 Kool
Jayme
Never mind,
I have discovered that exists a non documented property Array GridRow::DataItem[String ColumnName] which I am using.
I have got my KoolGrid working as expected.
Best regards.
Jayme Jeffman
Posted Feb 15, 2017 Kool
Hallie
Hi Jayme,
Can you please share how you got this to work? I would like to execute a different row color based on a value in a column. for example if status is inactive, display a grayed out look.
Any advice would be very helpful !
Thank you,
Posted Nov 1, 2017 Kool
Hallie
Hi Jayme,
Can you please share how you got this to work? I would like to execute a different row color based on a value in a column. for example if status is inactive, display a grayed out look.
Any advice would be very helpful !
Thank you,
Posted Nov 1, 2017 Kool
Hallie
Hi Jayme,
Can you please share how you got this to work? I would like to execute a different row color based on a value in a column. for example if status is inactive, display a grayed out look.
Any advice would be very helpful !
Thank you,
Posted Nov 1, 2017 Kool
Hallie
Hi Jayme,
Can you please share how you got this to work? I would like to execute a different row color based on a value in a column. for example if status is inactive, display a grayed out look.
Any advice would be very helpful !
Thank you,
Posted Nov 1, 2017 Kool
Hallie
Hi Jayme,
Can you please share how you got this to work? I would like to execute a different row color based on a value in a column. for example if status is inactive, display a grayed out look.
Any advice would be very helpful !
Thank you,
Posted Nov 1, 2017 Kool
Anthony Amolochitis
Here is the link to the method to apply the css to the row.
http://doc.koolphp.net/Controls/KoolGrid/PHP/GridRow/index.php#CssClass
If you are customizing your rows, then you may want to use other methods depending on the situation.
Posted Nov 1, 2017 Kool
Igor
Hi,
you can try something like this:
	// class MyGridEventHandler extends GridEventHandler
		// {
			// function OnRowPreRender($row,$args)
			// {
				// if ($row->DataItem['somedata'] <= 5 )
				// {
					// $row->CssClass = "red"; // Make the row in red color.}
				// }
				// else if ($row->DataItem['somedata'] >= 6 )
				// {
					// $row->CssClass = "green"; // Make the row in green color.}
				// }	
			// }
		// }
	// $grid->EventHandler = new MyGridEventHandler();
....
<style type="text/css">
.red
	{
		background-color:#99ccff;
	}
.green
{
	background-color:#99ccff;
}
</style>
Posted Jan 9, 2018 , edited Jan 9, 2018 Kool
Niks
Hi Hallie,
you can set as condition in MYSQL query for each record and the you can set on KoolGrid.php file function name is "_Render" there was line
$_tpl_td = "<td id='{id}' class='kgrCell {sorted} {visible} {cssclass} {cssclasses} ".$_row->DataItem['colorClassName']."' {valign}><div class='kgrIn' style='{wrap}{align}'>{cell}</div></td>";
$_tpl_td = "<td id='{id}' class='kgrCell {sorted} {visible} {cssclass} {cssclasses} ".$_row->DataItem['colorClassName']."' {valign}><div class='kgrIn' style='{wrap}{align}'>{cell}</div></td>";
add after {cssClass} ".$_row->DataItem['colorClassName']."' the "colorClassName" is from MYSQL script you can define as you want any think name
here .
Posted Dec 16, 2019 Kool