hi,
is it possible to color the rows different in a grid according to one or more columns?
thanks,
mati
hi,
is it possible to color the rows different in a grid according to one or more columns?
thanks,
mati
Re: rows in different colors?
You can change the color the cell text, but I do not see how to color the cell without using html codes directly in the code.
onRecord Event:
if ({id_status} == 3 ) {
sc_field_color('ticker','#ff0000'); // font color
sc_field_style('ticker','#000000'); // background color, behind text only .. not very useful.
} else { sc_field_color('ticker',''); } // defailt color
As mentioned, I guess you would have to color the table row in the onRecord event just like a html table row.
Re: rows in different colors?
The best I could come up with is the following code. The problem is the SC does not provide an ‘id’ to each data row in the grid. They provide an ‘id’ for the table and title, but not the data rows. Since I cannot attach to an ‘id’, the color will only change if key_field is the last record in the grid
<tr id="row1_id">
Perhaps someone with better CSS knowledge can jump in and provide a solution.
if ({key_field} == 1) {
echo "<style type="text/css">";
// depending on the grid row record is using ...
echo ".scGridFieldOdd { background-color: #ff0000; }";
echo ".scGridFieldEven { background-color: #ff0000; }";
echo "</style>";
}
Regards,
Scott
Re: rows in different colors?
I know it’s been while since this item was posted, but I was looking for the same thing and came up with this solution.
Put this into the onLoadRecord Event.
$nreg=$sc_seq_vert; // registry number
if (!($nreg&1)) // is even
{
$table="mytable"; // table which fields are shown
$odd_bgcolor="#E3E4FA"; // color: lavender
echo "<style type="text/css">";
echo "#idVertRow$nreg {background-color: $odd_bgcolor;}";
echo "#hidden_field_data_sc_seq$nreg {background-color: $odd_bgcolor;}";
echo "#hidden_field_data_sc_actions$nreg {background-color: $odd_bgcolor;}";
$result = mysql_query("DESCRIBE ".$table);
while ($row = mysql_fetch_row($result))
echo "#hidden_field_data_$row[0]$nreg {background-color: $odd_bgcolor;}";
mysql_free_result($result);
echo "</style>";
}
Hope this can help somebody else
Note: If your grid shows results from more than one table, this won’t work. Also, I’m working with Demo Version 5.02.0025… maybe the rows’ ID change between versions (look at the source code and adjust as needed).
Re: rows in different colors?
My bad… my solution works only for the application type “form” with the “Editable Grid view”.
Though for the Grid type, this version (5.02.0025) DOES makes a difference between odd and even rows.
Anyway, I think it’s still helpful.
Re: rows in different colors?
This is how I dealt with this.
As said before you can’t actually turn the background into a different color, only the background of the writing which looks rather poor if the writing is smaller than the field.
So what I did to give a colored grid effect was color a single column which does not appear have any writing in it (it does have writing but the writing is the same color as the background so you don’t see it). By adjusting the font size you can fill out the entire cell giving the effect of a real colored background. Only thing is you can’t write into it at the same time.
I put this into the ‘onRecord’ event:
if ($color ==“GREEN”) sc_field_style(‘Score’,’#478000’, ‘12px’, ‘#ffffff’, ‘Arial, sans-serif’, ‘bold’);
elseif ($color ==“AMBER”) sc_field_style(‘Score’,’#EABE00’, ‘12px’, ‘#000000’, ‘Arial, sans-serif’, ‘bold’);
elseif ($color ==“RED”) sc_field_style(‘Score’,’#D72700’, ‘12px’, ‘#ffffff’, ‘Arial, sans-serif’, ‘bold’);
Re: rows in different colors?
Strange behavior between sc_field_color and sc_field_style:
I want dinamically cheange the colors of single fiels in a grid application.
I saved all paramatres on database field called bgcolor and fgcolor
in a onRecord event i write:
sc_field_color(‘Name’,{fgcolor});
sc_field_style(‘Name’, {bgcolor} );
the first row is interpreted correctly
(html source code is: <font color="#FF0000"> …)
the second row is interpreted as:
<div style=“background-color:bgcolor;”> …
it does not write the content of field bgcolor but the field name!
Any idea on how to solve the issue?
Thanks.