Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Saturday, April 20, 2024
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Change row color based on contents of field

phpMyEdit Configuration     Change row color based on contents of field
Post new topic   Reply to topic   Goto page 1, 2  Next  
 
ericcron     Joined: 07 May 2004   Posts: 3  
Post Posted: 2004-05-07 20:17
Back to top  Reply with quote     

Just wondering if it's possible to change the row color based on the contents of a particular field.

Thoughts? Thanks for any suggestions.

Eric

 
nepto     Joined: 06 Jan 2003   Posts: 381   Location: Phoenix, Arizona (USA)
Post Posted: 2004-05-10 23:44
Back to top  Reply with quote     

This is actually work in progress:

http://opensource.platon.sk/projects/bug_view_advanced_page.php?f_bug_id=157

_________________
Ondrej Jombik (Nepto)
Visit my homepage , review my recent CV or projects and give me some feedback .
 
hbernard     Joined: 23 Mar 2003   Posts: 159   Location: FRANCE
Post Posted: 2004-05-16 14:53
Back to top  Reply with quote     

ericcron wrote:
Just wondering if it's possible to change the row color based on the contents of a particular field.

Thoughts? Thanks for any suggestions.

Eric


Well, nepto pointed out the correct bug report.

However, I think this is currently doable, using css options. (for the list mode)

$opts[’css’][’divider’] = 2; is PME default.

rows are outputted with css class like this :

row-......-0
row-......-1
row-......-0
row-......-1
row-......-0

If you use
$opts[’css’][’divider’] = 10000; (or any large number)
you have distinct class for all rows.

Then, you will need to ouput specific hidden css style for each row, using 'sql' for example.

Just an idea... But this should work.

_________________
hbernard - phpMyEdit updater.
 
ericcron     Joined: 07 May 2004   Posts: 3  
Post Posted: 2004-05-20 14:27
Back to top  Reply with quote     

Hi there,

thanks everybody for the responses. I think the first reply - applying style conditionally - almost does the trick. But - I would need a little more logic.

We have 2 fields, start and stop. I need to change the style of both fields if the current date falls between these two dates in start and stop.

In English,
If (todays.date >= Start) && (todays.date <= Stop)
change both start and stop to bold.

Looks like it could happen, I just don't know the syntax :)

Thanks again, phpmyedit is a great product -

Eric

 
ericcron     Joined: 07 May 2004   Posts: 3  
Post Posted: 2004-05-20 17:52
Back to top  Reply with quote     

Thanks Doug -

This appears to be working now...

Code:


$opts['fdd']['Start']['escape'] = false;
$opts['fdd']['Stop']['escape'] = false;

$opts['fdd']['Start']['sql|LF'] =
  'if( "'.date("Ymd").'" >= Start AND "'.date("Ymd").'" <= Stop ,
    CONCAT("<span style=\"color:#ff0000\">",
      Start,
        "</span>"),
          Start )';

$opts['fdd']['Stop']['sql|LF'] =
  'if( "'.date("Ymd").'" >= Start AND "'.date("Ymd").'" <= Stop ,
    CONCAT("<span style=\"color:#ff0000\">",
      Stop,
        "</span>"),
          Stop )';


But now the "highlighted" records don't sort properly, they always appear at the end of a list in ascending, or at the top of decending.

Anybody have any thoughts about why it would throw off the sort order?

 
chuny30     Joined: 13 Apr 2003   Posts: 6  
Post Posted: 2007-12-19 01:23
Back to top  Reply with quote     

What would be the reason why the contents of the CONCAT is being treated as a text string rather than html? The entire <span style....</span> is being displayed as is rather than the just the color code

doug wrote:
On a cell by cell basis you can conditionally apply style. This example compares today's date with the column named start_date. Dates in the past appear using red font color.

Code:
$opts['fdd']['start_date']['sql|LF'] =
  'if( start_date < "'.date("Ymd").'",
    CONCAT("<span style=\"color:#ff0000\">",
      start_date,
        "</span>"),
          start_date )';


 
chuny30     Joined: 13 Apr 2003   Posts: 6  
Post Posted: 2007-12-19 02:52
Back to top  Reply with quote     

Thanks Doug. Would it be possible to add an else clause in there as well?

doug wrote:
oops .... forgot this
Code:
'escape' => false


 
chuny30     Joined: 13 Apr 2003   Posts: 6  
Post Posted: 2007-12-19 03:04
Back to top  Reply with quote     

Should have been more specific, apologies. What I wanted was in your example of date comparison, would it be possible to change the color if the condition was met, but if not change the color to green or something?
doug wrote:
chuny30 wrote:
Would it be possible to add an else clause in there as well?


Huh?


 
pierig     Joined: 15 Apr 2009   Posts: 3  
Post Posted: 2009-04-15 16:01
Back to top  Reply with quote     

I have the same issue as "ericcron". In fact I have a list with bugs of a software we use and every row which includes "yes" in the field "Solved" should have another color than the "no" row.

The solution here just makes you the color of the textbackground and just one column. If you put the code for all fields it's looking acceptable, but sorting is not working properly.

I know it's an old story, but I'm searching since two days in your forum. I really like phpmyedit, please help me!


Last edited by pierig on 2009-04-15 19:27, edited 1 time in total

 
doug     Joined: 10 Feb 2003   Posts: 1013   Location: Denver, Colorado (USA)
Post Posted: 2009-04-15 17:55
Back to top  Reply with quote     

I don't have an answer for you, but do you really have a field named "Solved?" with a question mark in the field name? If so, that might be part of the sort problem. Punctuation might be legal for column names (no time to research that) but actually using punctuation other than underscore with MySQL field, table, or db names can cause all sorts of unexpected problems.

 
pierig     Joined: 15 Apr 2009   Posts: 3  
Post Posted: 2009-04-15 19:31
Back to top  Reply with quote     

Thanks doug for the quick answer.
Unfortunetly or fortunetly there's not question mark, I just did as usual, sorry.

I guess I really have the same issue as ericcron, so I thought there must be a logical reason..

Thanks for helping

 
pierig     Joined: 15 Apr 2009   Posts: 3  
Post Posted: 2009-04-20 10:38
Back to top  Reply with quote     

bump

 
amvarani     Joined: 22 Dec 2009   Posts: 5  
Post Posted: 2009-12-22 12:50
Back to top  Reply with quote     

I have the same 'sorting' problem here...

Any solution ?

 
jc8458     Joined: 23 Sep 2010   Posts: 2  
Post Posted: 2010-09-23 21:47
Back to top  Reply with quote     

Has anyone found a solution to this?

 
tbarmann     Joined: 22 Jun 2011   Posts: 1  
Post Posted: 2011-06-22 21:54
Back to top  Reply with quote     

This is an old thread, but I have found a simple solution using jQuery, a Javascript library, and am posting in the hopes that it will help others.

I had a phpmyedit table list view that contained a field with either a value of "Active" or "Cleared". I wanted to highlight in red any row that contained "Active."

All that's required is this jquery code in the head section of your page:

Code:
<script type="text/javascript">

$(document).ready(function () {
$('.pme-main tr').find('td:contains(\"Active\")').siblings().css('backgroundColor', 'red');
$('.pme-main tr').find('td:contains(\"Active\")').css('backgroundColor', 'red');
});
</script>


This searches through all table rows and looks for any cell that contains the word "Active." It then changes the backgroundcolor css value for its siblings (all the other <td>s in that row.) The second line changes the background color of the cell itself.

Note - The first code snippet I tried changed the background color of the parent <tr>. But that didn't work as I was using a css stylesheet that defined the background color for each cell, so it took precedence over the css of the parent.

Of course, you'll need to include a call to jquery in your table editing file. This example pulls in the latest version from jquery.com. You may want to use another source, or just download your own copy and store it on your server.
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>


This solution also does not interfere with phpmyedit column sorting.


ericcron wrote:
Just wondering if it's possible to change the row color based on the contents of a particular field.

Thoughts? Thanks for any suggestions.

Eric


 
Post new topic   Reply to topic   Goto page 1, 2  Next  

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy