DaDaBIK
This forum is devoted to the discussion about the software DaDaBIK database front-end
the PHP Database application generator for MySQL, PostgreSQL and SQLite; also available for Wordpress.

Welcome! Log In Create A New Profile

Advanced

row colors

Posted by mario2710 
row colors
February 16, 2011 09:08AM
in the css file the rowcolors are defined by:

/
* 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;
}

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:

td.status.new {
    color:green;
}
td.status.closed {
    color:red;
}
td.status.open {
    color:blue;
}

So how can I change the table output not to display the alternating rowcolors but the field based colors?
Re: row colors
February 16, 2011 04:23PM
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:
.status-new {
    color:green;
}
.status-closed {
    color:red;
}
.status-open {
    color:blue;
}
.status-none {
    color:black;
}

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.

		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

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.

_______________________________
..:: Debbie |\.-./| DaDaBIK Support ::..
Re: row colors
February 17, 2011 09:10AM
Hello DebbieS,

thank you very much for your reply. I've made the changes and it works thumbs up, 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??
Re: row colors
February 17, 2011 09:19AM
Never mind, I found it already, changed color to background-color tongue sticking out smiley
Re: row colors
February 17, 2011 06:40PM
I only used "color:" as that is what your original post indicated.
Glad you got it working!

_______________________________
..:: Debbie |\.-./| DaDaBIK Support ::..
Sorry, only registered users may post in this forum.

Click here to login