1

I am attempting to add some styling to a table in Code Igniter, I realize CI has a built in table library to help achieve this. I'm unsure how to implement this in my specific implementation however. I'm looking to incorporate these inbuilt functions:

$this->load->library('table');
$this->table->set_heading(array('Name', 'Color', 'Size'));

How can I add those functions in my specific implementation?

I have the following controller:

    public function ecomma(){

        $this->load->model('report_model');
        $data ['query'] = $this->report_model->generate_ecomm_data_report();

        $this->load->view('report_view', $data);    
}

My view:

<table>
<tbody>

<?php foreach($query as $row): ?>
<tr>

    <td><?php echo $row->no_skus; ?></td>
    <td><?php echo $row->brand; ?></td>
    <td><?php echo $row->unique_models; ?></td>

</tr>
<?php endforeach; ?>

</tbody>
</table>

1 Answer 1

1

Using the Table library is quite easy. This example requires that generate_ecomm_data_report()returns the results of a query. For example:

return $this->db->query('YOUR QUERY HERE');

Controller:

public function ecomma(){
    $this->load->library('table');
    $this->load->model('report_model');

    $query = $this->report_model->generate_ecomm_data_report();

One advantage to the Table library is that styling is quite easy using the template scheme of the class. For instance to add a CSS class to the header and to rows.

controller continues:

    $my_styles = array(
              "thead_open" => "<thead class='my_style'>",
              "row_start' => '<tr class='my-row-style'>");
    $this->table->set_template($my_styles);

    $this->table->set_heading(array('Name', 'Color', 'Size'));
    $data[table] = $this->table->generate($query);

    $this->load->view('report_view', $data);    
 }

View:

 <?php echo isset($table) ? $table : "No Data"; ?>

The result will be a table structure like the one you create in the foreach loop - only this one has style.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.