Welcome Guest, Not a member yet? Register   Sign In
HTML Table class: adding attritbutes to table cells not documented
#1

[eluser]Bramme[/eluser]
Hi everybody

I'm playing with the html table library and found something missing in the documentation. I'm building tables from a database table, but wanted to add a row "No data found" when the database is empty. However, I found out the HTML then generated is a little faulty.

When doing
Code:
$this->CI->load->library('table');

$query = $this->CI->db->get($table_name);
if ($query->num_rows() == 0)
{
    $this->CI->table->add_row('No data found');
}    
$return = $this->CI->table->generate($query);
You get something like
Code:
<table>
  <thead>
    <tr>
      <th>column</th>
      <th>column</th>
      ...
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>No data found</td>
    </tr>
  <tbody>
</table>
A more desired output would be that the "No data found" cell had a colspan attribute that matches the total amount of columns in the html table. So I checked out the core library and noticed that you can send a multidimentional array to add_row() to set attributes to the <td>, as long as one of the array keys is "data", like so:
Code:
$row = array(
    array(
        'data' => 'No data found',
        'colspan' => '2'
    )
);

$this->CI->table->add_row($row);

Now, before making this a bug report, I'd like to discuss this a little if possible, because I think it's not exactly the best way of handling it... Using a "data" key seems a little unclear to me.

I personally feel something like
Code:
$row = array(
    'No data found' => array(
        'colspan' => '2',
        'class' => 'double'
    ),
    'Third column cell without attritubes'
);

$this->CI->table->add_row($row);
would be better.

Even if my suggested array structure isn't accepted, I still feel this should be documented for future reference.




Theme © iAndrew 2016 - Forum software by © MyBB