Welcome Guest, Not a member yet? Register   Sign In
HTML table class
#1

[eluser]Josssi[/eluser]
Hi people,

did you ever create somebody table with for assistance of this class? Could you somebody to send me your table template and .css file for inspiration please?

Thanks a lotSmile
#2

[eluser]InsiteFX[/eluser]
Can also be in your normal Controller.
As far ass css you just style the fields the way you want and add the classes to the html tags below.
Code:
class MY_Controller extends CI_Controller {

  public function __construct()
  {
   parent::__construct();

  $this->load->library('table');

  $tmpl = array (
   'table_open'  => '<table border="0" cellpadding="4" cellspacing="0">',

   'thead_open'  => '<thead>',
   'thead_close'  => '</thead>',

   'heading_row_start' => '<tr>',
   'heading_row_end' => '</tr>',
   'heading_cell_start' => '<th>',
   'heading_cell_end' => '</th>',

   'tbody_open'  => '<tbody>',
   'tbody_close'  => '</tbody>',

   'row_start'  => '<tr>',
   'row_end'  => '</tr>',
   'cell_start'  => '<td>',
   'cell_end'  => '</td>',

   'row_alt_start'  => '<tr class="alt">', // <-- alt css class
   'row_alt_end'  => '</tr>',
   'cell_alt_start' => '<td>',
   'cell_alt_end'  => '</td>',

   'table_close'  => '</table>'
  );

  $this->table->set_template($tmpl);
}
}
#3

[eluser]Josssi[/eluser]
thank you very much for reaction. And what for are good this rows bellow?

<code>
'thead_open' => '<thead>',
'thead_close' => '</thead>',
</code>
and
<code>
'tbody_open' => '<tbody>',
'tbody_close' => '</tbody>',
</code>

I didnt met this rows in guide and havent ever use something like that. What is function of it?
#4

[eluser]Josssi[/eluser]
ok, i am sorry for my amateurs question, now i read something about thead and tbodyWink...first of all in your advice i read it as THREAD so i was out what a thread have i use Big Grin...My main problem is that i dont know how to send data into my table template. I used next rows:
<code>
$this->table->set_template($tmpl);

echo $this->table->generate($query);
</code>

I past your template into controller but my table looks everytime same. Whether i use them or not. I think that i make something wrong with sending applying tamplet on my data. Havent you got any other advice for me please?
#5

[eluser]InsiteFX[/eluser]
You use $this->table->add_row(); to add data to the table, you can also add data using a foreach loop

See the HTML Table Class below:
CodeIgniter Users Guide - HTML Table Class

#6

[eluser]Josssi[/eluser]
I read it all, but i am a litle bit mixed of them. I dont understant if I can use my own template if I want to generate dynamic table, where data are of database. I can get db-data, and i cat view them. Now if i use template which pasted you above, will i see changed my table? If yes, so I am doing something wrog :/.
#7

[eluser]InsiteFX[/eluser]
You can call a method in your model and return a result_array() and loop through it to a to the table.
Something like this:
Code:
// Grab an array of users from the database
    $data = $this->model->get();

    // Setting headings for the table
    $this->table->set_heading('Name', 'Email', 'Actions');

    foreach($data as $value => $key)
    {
        // Build actions links
        $actions = anchor("controller/edit/".$key['id']."/", "Edit") . anchor("controller/delete/".$key['id']."/", "Delete");

       // Adding row to table
       $this->table->add_row($key['name'], $key['email'], $actions);
    }
#8

[eluser]Josssi[/eluser]
Thank you for advice Wink...i am gonna to make new topic about one more problem which i am solving now. I will be pleased of your reactions Wink




Theme © iAndrew 2016 - Forum software by © MyBB