Welcome Guest, Not a member yet? Register   Sign In
Adding a ID to a Table Row
#1

[eluser]whobutsb[/eluser]
Morning all,
I just have a quick question. Is there a way to add a unique id to a table row using the $this->table->add_row() method? I know you can use the $this->table->template() method to set an id or class to all of the rows, but I would like to add a different id to each row so that I can do drag and drop sortables with jQuery, and serialize the order.

Thank you for the help!

Steve
#2

[eluser]gtech[/eluser]
ignore me I got the wrong end of the stick
#3

[eluser]TWP Marketing[/eluser]
whobutsb,
I don't think add_row() will work for this. If your table structure does not contain a unique ID, adding a new row (new record) will only add a row with the default structure.

Best solution: Can you edit the db? Add an ID field (unique, autonumber, integer...).

If you cannot edit the db, could you read the table into an array and sort it in memory? This is not the best solution if your table is large...
#4

[eluser]whobutsb[/eluser]
Hmm it looks like I have a feature request for CI 1.7.2. It would be very handy to be able to add attributes to a <tr> and even a <td>. Does anyone know if this feature has already been requested?


Thanks for the help!
#5

[eluser]jedd[/eluser]
Ah, the delightful ambiguity of the word table. Smile

I see two broad options - assuming you've checked out the SVN for the next rev of CI and found it wanting ...

First, and my preferred, is write your own table view snippet. It's arguable that the CI table class shouldn't be used as it generates HTML within your controller, and this kind of goes against the grain. It's also pretty lacking - as you've discovered - when you want to do something a bit more interesting. So, write a library or helper wrapped around a view snippet, or just make your view snippet beautiful and drop data straight into it.

Second, extend the table class (or even replace its entire functionality).




Theme © iAndrew 2016 - Forum software by © MyBB