CodeIgniter: Ability to add HTML attributes to a table row such as class or id

It is annoying that CodeIgniter’s HTML Table class does not support the ability to add attributes to the table rows such as classes, ids and data-attr. Using something like the Twitter BootStrap you may be wanting to add classes to the rows so that you can style rows that are success, errors or warnings.

I decided that this is crazy and that the rows should work the same as the cells. I have posted two options on GitHub to overcome the problem:

  1. Extend the Table class -> -> add MY_Table.php to application/libraries folder
  2. Replace the Table class -> -> replace CI_Table.php in system/libraries folder (please comment and push for this to be pulled)
  3. Despite which solution you chose you can add the HTML attributes to the table row using 1 of two methods:

        $rows[]=array('data'=>$row, 'class'=>'warning');
        echo $this->table->generate($rows);


        $this->table->add_row(array('data'=>$row, 'class'=>'warning'));

    So you may want to do something like:

        foreach($people as $person)
            $this->table->add_row(array('data'=>$row_data, 'class'=>$person->status));
        $this->table->set_heading(array('Given name','Family Name', 'City'));
        echo $this->table->generate($rows);