Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED] Table library question: cell/column width / library hack
#1

[eluser]Laszlo Breda[/eluser]
This is my first, so I must start with saying that CI is a really great framework and hats off the developers and community! I'm porting our company's site to CI now and even though we need some light CMS functionality, I'm much more comfortable working with CI than fighting with CMS sw for our non-CMS static and php stuff. Only other candidate was/is MODx.

Okay, on to the question:
I've been using the html table class and it's been great except I was unable to specify the column width individually. I hacked the library so now it's working fine, setting the width is painless. Of course, with the new version out, I had to carry over the hack.

1. Any official way to set the width that I haven't noticed?
2. Or is it possible to make these hacks upgrade-safe? Perhaps with the new extension (MY_) feature?

Thanks,
Laszlo
#2

[eluser]wiredesignz[/eluser]
Upgrade safe means you should always use the MY_ prefix for your application/libraries which hack the CI core.
#3

[eluser]Laszlo Breda[/eluser]
[quote author="wiredesignz" date="1203091826"]Upgrade safe means you should always use the MY_ prefix for your application/libraries which hack the CI core.[/quote]

Yeah, but that' with the new 1.6 version and haven't looked into it yet. Plus, one of my modifications is one extra line of code inside the main (long) cell renderer function, which I guess would be awkward to hook. That's why I was hoping there's built-in cell width support.
#4

[eluser]xwero[/eluser]
I think if you are going to set the cell width you best create a static header of your table with the width for the appropriate column and use the table library as follows
Code:
$this->load->library('table');
$tmpl = array ( 'table_open'  => '','table_close' => '' );
$this->table->set_template($tmpl);
foreach($data as $row)
{
  $this->table->add_row($row['field1'], $row['field2'], $row['field3']);
}
echo $this->table->generate();

edit : i'm not sure if the header is not going to be created because i don't use the library.
#5

[eluser]Laszlo Breda[/eluser]
[quote author="xwero" date="1203096407"]I think if you are going to set the cell width you best create a static header of your table with the width for the appropriate column and use the table library as follows
Code:
$this->load->library('table');
$tmpl = array ( 'table_open'  => '','table_close' => '' );
$this->table->set_template($tmpl);
foreach($data as $row)
{
  $this->table->add_row($row['field1'], $row['field2'], $row['field3']);
}
echo $this->table->generate();

edit : i'm not sure if the header is not going to be created because i don't use the library.[/quote]

Thanks, xwero, I didn't think of a pure html solution. You reminded me to put an empty row on top of the table and set the display property of the row to none (or use a css class):

<tr style="display:none;">
<td width="100">column 1</td>
<td width="200">column 2</td>
<td> column 3</td>
</tr>

Being paraniod, the only question that remains: is <tr style="display:none;"> supported by all browsers?
#6

[eluser]xwero[/eluser]
yes display none is supported by all browsers except for the ones who don't render css styles Wink
#7

[eluser]sophistry[/eluser]
was your table fix anything like this:

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

[eluser]Laszlo Breda[/eluser]
[quote author="sophistry" date="1203110047"]was your table fix anything like this:

http://ellislab.com/forums/viewthread/50198/[/quote]

Well, I originally hacked the Table lib with a set_cell_width() function and a little modification to the generate() function. But now it's even simpler: I just added micro-helper (actually a function to my site helper script):

Code:
// Returns hidden html row tag for tables to set column widths
// $show: false if row should be hidden
// $ruler: true if a pixel ruler is needed as background for testing
//
// Provide additional width parameters as needed starting with leftmost column
// Pass -1 for cells without width attribute for auto size

function insert_column_width ($show=false, $ruler=false)
{
    $args = func_get_args();
    
    // Nothing to do if not enough parameters
    if (count($args) > 2) {
        // Generate <tr> tag
        $str = '<tr'
             . ($show ? '' : ' style="display:none;"')
             . (($ruler && $show) ? ' background="/images/pixel-ruler.png"' : '')
             . '>';
        // Generate <td> tags        
        for ($i=2; $i<count($args); $i++) {
            $str .= '<td'
                 . ($args[$i] < 0 ? '' : (' width="' . $args[$i]) . '"') . '>'
                 . ($ruler ? '&nbsp;' : $args[$i]) . '</td>';
        }
        // Wrap up row
        $str .= '</tr>';
    }
    return $str;
}

I hate tables and always mess with sizes so I added an optional ruler for testing (see pic). Who knows, maybe someone else is fighting with tables, too and finds this usefulSmile

Cheers,
LB
#9

[eluser]Chris Newton[/eluser]
Whoah that's cool I'm going to have to check that out.




Theme © iAndrew 2016 - Forum software by © MyBB