Welcome Guest, Not a member yet? Register   Sign In
Using the HTML Table Class
#11

[eluser]Crimp[/eluser]
Everything is optional ;-)

My opinion on the table class changed radically when I started thinking about what it could do for me and not how it could, or could not, re-generate exactly what I was already doing. Sometimes it's the coder and not the supplied CI classes that are weak. This was, arguably, one such case for me. There is potential in the table class in more ways than one.
#12

[eluser]xwero[/eluser]
The class does what it does like it's advertised so if you don't want to use it, don't. That is true.

But i think there is room for improvement like for instance instead of having to change most of the template the possibility of adding a static template to the class. It would make it more designer friendly too.
#13

[eluser]Unknown[/eluser]
[quote author="Crimp" date="1205331727"]I am using this class a lot in a current project. Combined with the jQuery tablesorter plug-in, it makes for quick and easy backend sections. A tip is to "cheat" with your template to make the generated table tablesorter compatible, and then you've saved yourself from typing a trillion trs and tds.

Code:
$tmpl = array (
                        'table_open'        => '<table id="' . $table_id . '" cellpadding="0" cellspacing="0" border="0">',
                        'heading_row_start'    => '<thead><tr>',
                        'heading_row_end'    => '</tr></thead><tbody>',
                        'heading_cell_start'=> '<th class="header">',
                        'heading_cell_end'    => '</th>',
                        'row_start'            => '<tr>',
                        'row_end'            => '</tr>',
                        'cell_start'        => '<td>',
                        'cell_end'            => '</td>',
                        'row_alt_start'        => '<tr>',
                        'row_alt_end'        => '</tr>',
                        'cell_alt_start'    => '<td>',
                        'cell_alt_end'        => '</td>',
                        'table_close'        => '</tbody></table>'
                    );
[/quote]

Wow, just what I need to get it working (integration with jQuery tablesorter)... thanks!! That's a really neat trick!! ;-)
#14

[eluser]HdotNET[/eluser]
just spent an hour or so playing/extending the table class myself... I think I've managed to extend it without actually breaking it.

its too big to post here, so click this:

http://www.capitalh.net/codesamples/CI_Table.txt

new(ish) template, allowing a bit of search/replace within certain tags:

Code:
array (
'table_open'         => '<table border="0" cellpadding="4" cellspacing="0"%s>',

'heading_row_start'     => '<tr>',
'heading_row_end'         => '</tr>',
'heading_cell_start'    => '<th>',
'heading_cell_end'        => '</th>',

'row_start'             => '<tr>',
'row_end'             => '</tr>',
'cell_start'            => '<td%s>',
'cell_end'            => '</td>',
'column_heading_cell_start'    => '<th%s>',
'column_heading_cell_end'    => '</th>',

'row_alt_start'         => '<tr>',
'row_alt_end'             => '</tr>',
'cell_alt_start'        => '<td%s>',
'cell_alt_end'            => '</td>',
'column_heading_cell_alt_start' => '<th%s>',
'column_heading_cell_alt_end'    => '</th>',

'table_close'             => '</table>'

)


basically you can now set various params for any cell in a row, even turning it into a th cell if need be:

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

$this->table->set_summary('This is a summary'); // you needs this to make a table validate, innit.
$this->table->set_caption('This is a caption');
$this->table->set_heading('','heading 1','heading 2','heading 3','heading 4');


for($c=1;$c<31;$c++){

    $this->table->add_row_clever(
    array('type'=>'heading','content'=>$c,'width'=>150,'height'=>10,'param'=>'style="color:green"') //th type row
    ,'a',
    array('content'=>'B','param'=>'style="color:red"') // td type row
    ,
    'c',
    'd'
    );
    // normal add row
    //$this->table->add_row($c.'z','a','b','c','d');

}


echo $this->table->generate();

look in the function generate(), which is where the clever stuff happens. also fiddled _compile_template to allow the new template fields... it should all be backwards compatible methinks


I'm off to the pub... post any improvements back here.
#15

[eluser]dannythebestguy[/eluser]
Thanx a ton... For the solution...
#16

[eluser]Unknown[/eluser]
nice table




Theme © iAndrew 2016 - Forum software by © MyBB