Welcome Guest, Not a member yet? Register   Sign In
about td width in Table Library
#1

[eluser]Unknown[/eluser]
in ci table, i can't set individual td width.
so i try to rewrite Table.php,
though i know it's not good to rewrite system code, but it solved my problem.
if it's a wrong way or any suggestion, please just tell me.

rewrite code as follow,
step0-backup Table.php

step1-add a width array
Code:
var $heading_width= array();

step2 -add set_heading_width function
Code:
function set_heading_width()
    {
        $args = func_get_args();
        $this->heading_width = (is_array($args[0])) ? $args[0] : $args;
    }
step3-rewrite clear()
Code:
function clear()
    {
...
        // add this line
        $this->heading_width            = array();
...
    }
step3-rewrite generate()
in // Build the table rows section
rewrite
Code:
$out .= $this->template['cell_'.$name.'start'];
to
Code:
str_replace('>',' width="'.$this->heading_width[$j].'">',$this->template['cell_'.$name.'start']);

it will be like this

Code:
function generate($table_data = NULL)
    {
    ...
        // Build the table rows
        if (count($this->rows) > 0)
    ...
                $j = 0;  // add this line
                foreach($row as $cell)
                {
                    //$out .= $this->template['cell_'.$name.'start']; // replace this line as follow
                    $out .= str_replace('>',' width="'.$this->heading_width[$j].'">',$this->template['cell_'.$name.'start']);
    ...

                    $out .= $this->template['cell_'.$name.'end'];
                    $j++;  // add this line here
                }
    }

finally load your new as before
then add this line ,
Code:
$this->table->set_heading_width('20px', '120px', '150px');
you will get a widthize table


ps. if you don't add the last line, it cause some error, next step, i will add debug code in Table.php
#2

[eluser]sophistry[/eluser]
hi seikai and welcome to CI...

some parts of CI core are so (ahem) "stable" they barely move at all.
viz., i posted a similar upgrade to the table class 2 1/2 years ago.

http://ellislab.com/forums/viewthread/50198/

enjoy.
#3

[eluser]Andrew Ul'din[/eluser]
thanks! it is work!

some update
Code:
$out .= str_replace('>',' width="'.$this->heading_width[$j].'">',$this->template['cell_'.$name.'start']);

change width to style

Code:
$out .= str_replace('>',' style="'.$this->heading_width[$j].'">',$this->template['cell_'.$name.'start']);

like that and you can set any style to the td. for example

Code:
$this->table->set_heading_width('width: 20px;', 'width: 120px; background: #efefef;', 'cursor: pointer;');

enjoy! Smile




Theme © iAndrew 2016 - Forum software by © MyBB