Specify class when adding data to table |
[eluser]Jay Gridley[/eluser]
Hi foks, I am using HTML Table class in CI and I am filling table using table->add_row() method.. Is possible to specify class for each table cell? Something like Code: $item1 = array('data' => 'mydata', 'class' => 'first'); Any ideas? Thanks a lot!
[eluser]falkencreative[/eluser]
What's the reasoning for this? Just for zebra striping? (highlighting alternate rows in the table) You can use the "cell_start" and "cell_start_alt" within set_template() for this (http://ellislab.com/codeigniter/user-gui...table.html). If not... I imagine you could extend the table library to do this. I did something like this just recently, except I was adding attributes to the <th> tags. It's not 100% ready to be released yet, but with a bit more tweaking I should be able to release it and you could do something based on the ideas in my code.
[eluser]Jay Gridley[/eluser]
Reason is aligning cells due to its content...text to left, numbers to right etc..let me know when you are ready to release it, I will look at it for inspiration :-)
[eluser]falkencreative[/eluser]
I should be finishing it up shortly (in the next day or two) so I'll let you know.
[eluser]falkencreative[/eluser]
Here's how I extended the library to be able to add attributes (classes, ids, etc) to the <th> tag: Let me know if you have questions. I'll probably be writing a proper blog post on this, and perhaps if I have the time modifying it to add the option to add classes to each of the <td> tags as well. "MY_Table.php" (placed within application/libraries, extends the Table library) Code: <?php
[eluser]falkencreative[/eluser]
To test this out, here's a sample controller/view to demonstrate to use the revised library: My controller: Code: <?php My view: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
Welcome Guest, Not a member yet? Register Sign In |