Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter HTML table generator with custom layout inside

CI table->generate($data1, $data2, $data3) will output my data in a form of simple table like:

<table>
    <tr>
        <td>data1</td>
        <td>data2</td>
        <td>data3</td>
    </tr>
</table>

What if I need a complex cell layout with multiple $vars within each cell:

$data1 = array('one', 'two', 'three'); 

and I want something like this:

<table>
    <tr>
        <td>
            <div class="caption">$data1[0]</div>
            <span class="span1">$data1[1] and here goes <strong>$data1[2]</strong></span>
        </td>
        <td>...</td>
        <td>...</td>
    </tr>
</table>

How should I code that piece?

For now I just generate the content of td in a model and then call generate(). But this means that my HTML for the cell is in the model but I would like to keep it in views.

like image 568
eugene.inspired Avatar asked Jun 19 '26 20:06

eugene.inspired


1 Answers

What I would suggest is have a view that you pass the data that Generates the td structure. Capture the output of the view and pass this to the table generator. This keeps your structure in the view albeit a different one.

like image 189
Hailwood Avatar answered Jun 21 '26 09:06

Hailwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!