tbarmann
Založený: 22.06.2011
Príspevky: 1
Zaslal: 2011-06-22 21:59
Návrat hore
Odpovedať s citátom
|
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:
Kód: |
<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.
Kód: |
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> |
This solution also does not interfere with phpmyedit column sorting.
ericcron Napísal: |
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 |
|
tbarmann
Založený: 22.06.2011
Príspevky: 1
Zaslal: 2011-06-22 22:09
Návrat hore
Odpovedať s citátom
|
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:
Kód: |
<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.
Kód: |
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> |
This solution also does not interfere with phpmyedit column sorting.
ericcron Napísal: |
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 |
|
Alan
Založený: 10.07.2012
Príspevky: 2
Zaslal: 2012-07-10 04:50
Návrat hore
Odpovedať s citátom
|
Hi tbarmann,
Thanks for sharing the code, it really helps.
I did my first-ever coding this week only, and was able to integrate your solution in my phpedit generated page. Yet I have a small issue :
This part of your code
Kód: |
$('.pme-main tR').find('td:contains(\"SPECIFIC\")').css('backgroundColor', 'green');
|
says
"if any cell in the table contains SPECIFIC, then make it's background color GREEN"
whereas I need to implement the following rule :
"if any cell in the table's
third column only
contains SPECIFIC, then make it's background color GREEN",
Because some of my column's cells contain similar text (it's a necessity) while they refer to very different things, I'd like to apply a set of rules cell per cell, but inside the strict context of a specific column.
This way, I'd be able to declare :
"if any cell in the table's
first column
contains "A", then make the background of this cell Red,
if any cell in the table's
second column
contains "A", then make the background of this cell Blue,
if any cell in the table's
third column
contains "A", then make the background of this cell Green,
etc.
Could someone help me out ?
Thanks again :)
|
raulrm
Založený: 01.05.2012
Príspevky: 3
Zaslal: 2013-01-11 18:51
Návrat hore
Odpovedať s citátom
|
I'd realize that the sql method dosn't work on columns whith table lookup.
In my case the jquery solution produce artifacts because the word searched for is a very common one.
As a workaround, finaly I choose to change the description field on lookut table to include CSS formating.
ex:
Kód: |
CREATE TABLE IF NOT EXISTS `rc_estado` (
`id` int(11) ,
`estado` varchar(100),
PRIMARY KEY (`id`)
);
INSERT INTO `rc_estado` (`id`, `estado`) VALUES
(1, '<span style="color:green;background-color:yellow;font-weight:bold;">CREADO</span> ');
$opts['fdd']['status_oc'] = array(
'name' => 'Estado:',
'default' => 1,
'escape' => false,
'values' => array(
'table' => 'rc_estado',
'column' => 'id',
'description' => 'estado',
|
This work very well for me.
If you use 'rc_estado' table in another columns/pages when only the value of estado field is needed (whithout the style) you must use htmlspecialchars() or 'escape' => true to filter it
|
cindyxyr11
Založený: 07.09.2022
Príspevky: 15
Zaslal: 2022-09-07 12:06
Návrat hore
Odpovedať s citátom
|
A team of highly trained, certified, and experience truck repair professionals.
Irvine Mobile Truck Repair Company
|
nathanmau90
Založený: 08.09.2022
Príspevky: 26
Zaslal: 2022-09-08 04:08
Návrat hore
Odpovedať s citátom
|
When it comes to new construction or a major renovation, the concrete work is some of the most important.
Newport News Concrete Company
|
Odoslať novú tému
Odpovedať na tému
Choď na stránku Predchádzajúci 1, 2
|
|