Welcome Guest, Not a member yet? Register   Sign In
Add columns to HTML Table Class

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?


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:

But you can find all this info in the User Guide, that's a very good one!

Thanks for your reply,

this is the way i create the table(controller):

$this->data['results'] = $this->gestionmodel->listarpaquetes($config['per_page'],$this->uri->segment(3));
$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_heading('ID', 'Titulo', 'Fecha Inicio', 'Fecha Fin','Fecha Auto Publicacion','Fecha Auto Despublicacion','Publicado','Editar');


And in my view:
&lt;?php echo $this->table->generate($results); ?&gt;

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

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:

//Model database query before this
$query = $this->db->query('mytable',$limit,$offset);
  foreach($query->result() as $row){
     $data[] = array(
        //... all field results you may want
return $data;

Of course if you want to work this in your controller you have to use the add_row method in a foreach loop!
// in the controller
  foreach($data['results']->result() as $row){

The heading is ok, if your table template is assuming that!

ok,I see

thanks for your help!

Theme © iAndrew 2016 - Forum software by © MyBB