|
 Csík Csaba - 2017-02-27 17:17:14
How to make Row_color_even and Row_color_odd?
Thank you.
 Alexandre Sinício - 2017-02-27 17:39:40 - In reply to message 1 from Csík Csaba
Hi!
Probably the simplest way is to use a CSS selector, like this:
tr:nth-child(even) {
background: #CCC
}
tr:nth-child(odd) {
background: #777
}
If, by any reason, this solution is NOT acceptable, you could use a custom function. It is a MUCH more complicated solution, but should do the work. Something like this:
$rowCounter = 1;
$trClassesFunction = function($row) {
global $rowCounter;
$isOdd = ($rowCounter % 2 == 1);
$rowCounter++;
if ($isOdd) {
return "row_is_odd";
} else {
return "row_is_even";
}
};
$table = new HTMLTable();
$table->setData($arrData); //YOUR DATA
$table->setHeaders($arrHeaders); //YOUR HEADERS
$table->setTrClassFunction($trClassesFunction);
echo $table->getHTML();
Now your odd TRs will have a "row_is_odd" class applied to then, and the even TRs will have the "row_is_even" class.
 Csík Csaba - 2017-02-28 09:20:18 - In reply to message 2 from Alexandre Sinício
Thank you work fine, but not good for me becouse i use lot of table my page menu item etc. Please help my. Thank you.
 Alexandre Sinício - 2017-02-28 12:32:16 - In reply to message 3 from Csík Csaba
I am not understanding well the problem you are facing. Could you ellaborate a little more?
- if what you need is "all even/odd rows of all tables should be painted with color x/y", than a simple CSS selector ("tr:nth-child(even){}", for example) should do the job;
- if what you need is "all even/odd rows of a SPECIFIC table should be painted with color x/y", than just put an ID on your table. Then, a simple CSS selector ("#yourTable tr:nth-child(even){}", for example) should do the job;
If what you need is something different, just reply and we'll try to figure out together.
 Csík Csaba - 2017-02-28 14:48:47 - In reply to message 4 from Alexandre Sinício
i use tr tag my menu and i use tr tag my page separator.
look at this picture. (after - before):
imgur.com/a/JuXK2
 Csík Csaba - 2017-02-28 15:11:49 - In reply to message 4 from Alexandre Sinício
sorry i understanding css. Thank you for your help.
 Alexandre Sinício - 2017-02-28 16:04:30 - In reply to message 6 from Csík Csaba
Without seeing you code... I assume you have something like this:
FIRST TABLE
<table>
<tr>........</tr>
<tr>........</tr>
</table>
SECOND TABLE
<table>
<tr>........</tr>
<tr>........</tr>
</table>
Change to something like this:
FIRST TABLE
<table id='table1'>
<tr>........</tr>
<tr>........</tr>
</table>
SECOND TABLE
<table id='table2'>
<tr>........</tr>
<tr>........</tr>
</table>
Then, include this CSS snippet:
#table1 tr:nth-child(even) {
background-color: red;
}
#table1 tr:nth-child(odd) {
background-color: blue;
}
#table2 tr:nth-child(even) {
background-color: green;
}
#table2 tr:nth-child(odd) {
background-color: yellow;
}
Let me know if it helped.
 Csík Csaba - 2017-02-28 16:14:24 - In reply to message 7 from Alexandre Sinício
Thank you. but i use your classes PHP Array into HTML Table how to set table id?
 Alexandre Sinício - 2017-02-28 16:48:10 - In reply to message 8 from Csík Csaba
Just use the setTableID() method.
Check out the "01_basic_usage.php" example provided. There you have the complete setup necessary!
 Csík Csaba - 2017-02-28 16:57:12 - In reply to message 9 from Alexandre Sinício
perfect. thank you. good work.
|