row colors

mario2710

New member
in the css file the rowcolors are defined by:

/[pre]
* result rows */
/* results_1 and results_2 differ only for the background-color, this create the alternate row colors effect */
.tr_results_1 {
font-size: 8pt;
vertical-align: top;
white-space: nowrap;
background-color: #EFEFEF;
}
.tr_results_2 {
font-size: 8pt;
vertical-align: top;
white-space: nowrap;
background-color: #ffffff;
}
[/pre]

I want the row colors to be defined based on a value pulled out of the database. So in my database there's a field called "status". Based on the content of that field I want the rowcolor to be displayed.

So I'm told this can be achieved by adding some styles and defining a variable which reads the field value:

[pre]
td.status.new {
color:green;
}
td.status.closed {
color:red;
}
td.status.open {
color:blue;
}
[/pre]

So how can I change the table output not to display the alternating rowcolors but the field based colors?
 

DebbieS

DaDaBIK Guru
In the build_results_table you can modify this by referencing the database value and then subsequent style based on the value from the database. Inside that function, you'll find a line that reads "while ($records_row = fetch_row_db($res_records)){", inside that you will see the existing style variables. Add / modify code to reference your database field and subsequent styles based on that field's value.

First, I'd change your style names to the following (your original will limit the style to ONLY td's and I'm not sure the double dot in the name would cause a problem or not:
[pre]
.status-new {
color:green;
}
.status-closed {
color:red;
}
.status-open {
color:blue;
}
.status-none {
color:black;
}
[/pre]

If it was my install, I'd add the following code in bold BELOW the existing results classes to ADD them to the alternating row colors so you can still have the alternating row colors and highlighting on mouseover etc, etc. the .= will add the additional class to the existing so long as there is a space included in the value. Be sure to change the $records_row["status"] part below to the actual case-sensitive name of the field you are referencing.

[pre]
if ($tr_results_class === 'tr_results_1') {
$td_controls_class = 'controls_2';
$tr_results_class = 'tr_results_2';
} // end if
else {
$td_controls_class = 'controls_1';
$tr_results_class = 'tr_results_1';
} // end else
$td_results_class = 'results_1';

if ($records_row["status"] === 'new') {
$td_controls_class .= ' status-new';
$tr_results_class .= ' status-new';
} // end if
elseif ($records_row["status"] === 'open') {
$td_controls_class .= ' status-open';
$tr_results_class .= ' status-open';
} // end elseif
elseif ($records_row["status"] === 'closed') {
$td_controls_class .= ' status-closed';
$tr_results_class .= ' status-closed';
} // end elseif
else {
$td_controls_class .= ' status-none';
$tr_results_class .= ' status-none';
} // end else
$td_results_class .= ' status_none';


// set where clause for delete and update
[/pre]

I've not tested this as I don't have an install that I can do that with, so give it a whirl and let us know how it works out for you.
 

mario2710

New member
Hello DebbieS,

thank you very much for your reply. I've made the changes and it works (tu), great.

However: your code changes the row in such a way that the background colour changes to white and the fontcolour gets the colour depending on the status. Is it possible to change the background colour of a row to the status colour instead of the font colour??
 
Top