• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[2Q] Doubts about Table Class and Form population

Hi everyone, i'm new using CI, and right now i'm developing something with it...

About the table class...
I'm generating a table from a database query, using the table template I add some attributes to my rows & headings, but that's only static data... I need to put some dynamic data..

For example, I need that my "<th>" has an "abbr" atrribute, that contains my database column name.. or have access to my data, in case that I need a link with my row id for example... It can be done with the table class?

About form population...
Is there a way to populate a form automatically based on an id? When i'm doing a CRUD process...

That's all (Sorry about my english, I'm from latin america)

If you use the table class you have to process the data before you pass it on.

The population of the form values is based on the the fieldname so if you name your fields like the column names in the database table it will be easy to create a CRUD form.

[quote author="xwero" date="1225113135"]If you use the table class you have to process the data before you pass it on.

The data it's alright.

Lets say my data is something like this...

Quote:Id Name
100 Something
200 Something else
150 Another thing

If i pass that to the table class it will generate the table as i want it to... But, what about if i want heading tag (<th>) has a property "abbr" that will be the heading name...

<th abbr="id">Id</th>....<th abbr="Name">Name</th>

If I use a template to add atributes to tags, it'll be stactic for every column...

The thing is how can i do to have dynamics atributes?

The table class isn't meant for highly dynamic tables. If your only concern is the header you can add the header in your view and let the table class take care of the data rows.

With processing data i was thinking about adding html to the 'raw' model data.
$data = $this->model->get_this();
foreach($data as $key => $row)
   if($row->id%2 == 0)
     $data[$key]->id = '<span class="even">'.$row->id.'</span>';
// use data to generate table

Thanx for your reply!!

You can also override the $table->generate method to use sprintf to generate your <th> or <td> tags.

foreach($this->heading as $heading)
    $out .= $this->template['heading_cell_start'];
    $out .= $heading;
    $out .= $this->template['heading_cell_end'];

foreach($this->heading as $heading)
    $out .= sprintf($this->template['heading_cell_start'], $heading);
    $out .= $heading;
    $out .= $this->template['heading_cell_end'];

Then, in your controller:
$tmpl = array (
    'heading_cell_start'  => '<th id="%s">'


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.