Welcome Guest, Not a member yet? Register   Sign In
adding database id's to table rows <tr>?
#1

[eluser]fivestringsurf[/eluser]
First off, this is my first post here as i just found code igniter and have been learning it all week. I was dead-against frameworks until I tried this one. It's fantastic. I was sold once i read the clear documentation with simple code examples Smile

Anyway... I'm pulling data from a db and would like to display it in tables. The code igniter table class does so much stuff with so few lines of code ( i always hated working with tables in php)

but here's the catch. I need to place some unique table information with each <tr> tag.
when using the set_template method it seems to set all the <tr>'s to the last template used. The templating is not honored each step of the row creation only according to last row templating set.

some code:
Code:
// get database results
                $db_results = $this->crud_books->read($dewey_num);
                
                //style table
                $dataArr = array('Title', 'Author', 'Year Published', 'Edition', 'Glossary');
                $this->table->set_heading($dataArr);
                
                //bulld table
                foreach($db_results->result() as $row){
                    //write unique books_id to onclick
                    $tmpl = array( 'row_start'   => '<tr on click="dialog('.$row->books_id.');">');
                    $this->table->set_template($tmpl);
                    $dataArr = array($row->title, $row->author, $row->year_published, $row->edition, $row->glossary);
                    $this->table->add_row($dataArr);
                
                }
                $data['bookData'] .=  $this->table->generate();
                $this->table->clear();

essentially i am using an onclick call inside of the <tr> of each row and need those onclick values i am passing to be the id's associated with the data written in each row.

Any advice on how to achieve this?
#2

[eluser]pickupman[/eluser]
Welcome to CI and the forums!

You can only set the template once. You will probably need to build the table like the old way, or put the book id in a column or in a hidden span in one of the cells. I would also suggest using inline javascript and checkout jQuery.
#3

[eluser]fivestringsurf[/eluser]
thought so; ok thanks
btw: i also recently adopted jquery into my existing workflow...
so now i officially use 2 frameworks.




Theme © iAndrew 2016 - Forum software by © MyBB