Add columns to HTML Table Class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Add columns to HTML Table Class (/showthread.php?tid=10193) |
Add columns to HTML Table Class - El Forum - 07-22-2008 [eluser]danilm[/eluser] Hi, I'm using HTML Table Class to create a table with the result of a select from database as well as pagination class. Everything goes fine except that I cannot include a link on every row to edit or delete it. Is there any way to add columns once the table is generated? or is there anyway to add values to the parameter that stores the query result from database? Thanks Add columns to HTML Table Class - El Forum - 07-22-2008 [eluser]hvalente13[/eluser] I guess you have to read the Table Class deeply in User Guide. Table Class But here goes a tip: When you load the table class, then you add rows, and the table will be built dynamically. So if you alter your code in the add_row line, you can manage to add more columns to it, like this: Code: $this->table->add_row('Column1','Column2','Edit_Action_Column','Del_Action_Column'); But you can find all this info in the User Guide, that's a very good one! Add columns to HTML Table Class - El Forum - 07-22-2008 [eluser]danilm[/eluser] Thanks for your reply, this is the way i create the table(controller): $this->load->model('gestionmodel'); $this->data['results'] = $this->gestionmodel->listarpaquetes($config['per_page'],$this->uri->segment(3)); $this->load->library('table'); $tmpl = array ( 'table_open' => '<table cellspacing="2" cellpadding="0" width="100%">', 'heading_row_start' => '<tr>', 'heading_row_end' => '</tr>', 'heading_cell_start' => '<th class=titulos_lista>', 'heading_cell_end' => '</th>', 'row_start' => '<tr class=par>', 'row_end' => '</tr>', 'cell_start' => '<td class=centrado>', 'cell_end' => '</td>', 'row_alt_start' => '<tr class=impar>', 'row_alt_end' => '</tr>', 'cell_alt_start' => '<td class=centrado>', 'cell_alt_end' => '</td>', 'table_close' => '</table>' ); $this->table->set_template($tmpl); $this->table->set_heading('ID', 'Titulo', 'Fecha Inicio', 'Fecha Fin','Fecha Auto Publicacion','Fecha Auto Despublicacion','Publicado','Editar'); $this->load->view('listado',$this->data); And in my view: <?php echo $this->table->generate($results); ?> What you're saying is to add rows instead heading? and then generating? do the table generates all the results without using foreach? thanks again Add columns to HTML Table Class - El Forum - 07-22-2008 [eluser]hvalente13[/eluser] Yes it does generate the table without foreach, but if you want to add more interactivity to your rows, like edit or delete actions, your data['results'] array must be configured to do that. I supose that your model is only retrieving the database results, but if you work it before passing it to controller you can manage the expected result as well: Code: //Model database query before this Of course if you want to work this in your controller you have to use the add_row method in a foreach loop! Code: // in the controller The heading is ok, if your table template is assuming that! Add columns to HTML Table Class - El Forum - 07-22-2008 [eluser]danilm[/eluser] ok,I see thanks for your help! |