Controlling column (field) width in Fabrik table

Wisdom Hunter

New Member
Hi, is there any way of controlling the width of columns (fields) in a Fabrik table ? I have a table with only 5 columns; one of them has a lot more text than the others and currently it is wrapping, which is OK but there is room for the column to be wider, so the text wouldn't have to wrap, and I don't know how to get it to do this. Is there a way ? Element width doesn't affect this, seemingly - I guess the element definition is used on the related form, not the table display - correct ?

BTW Should I be upgrading to Fabrik 2.0 - is it stable yet ? (I haven't been around for a while - busy with my "real job")

Thanks
 
hi

You would have to create a custom table template to do this:
copy views/table/tmpl/default

edit template.php in the copied folder

replace

Code:
<tr>
            <?php foreach($this->headings as $heading){?>
                <th><?php echo $heading;?></th>
                <?php }?>
            </tr>

with

Code:
<tr>
            <?php 
 $widths = array('100', '200', '400');
$i = 0;
foreach($this->headings as $heading){?>
                <th width="<?php echo $widths[$i];?>px"><?php echo $heading[0];?></th>
                <?php $i++;
}?>
            </tr>

replace $widths = array('100', '200', '400'); with a set of values that you want for each of your headings

As far as 2.0 goes - its beta - so not stable. There are less and less bugs each day but you would need to keep up with the svn, and i wouldnt use it on a live site. Oh and the upgrader is yet to be written to migrate from 1 to 2.

cheers
Rob
 
Thanks - don't know if I'll bother, but you've shown me what I need to do, and I appreciate knowing how to do this if I decide that it's important enough to take the trouble :)
PHP coding is still a bit of an adventure for me ... understand all the concepts but haven't had enough experience yet to be familiar with the syntax, so it always takes some time ...
Anyway, thanks a lot. Much appreciated. I like knowing how things work ...
 
Played with it some, couldn't get it to work (Yet) ... but did find that the text I enter for the column label (Not the data in the column) governs width of display.
 
FYI this is the code I used :

Code:
   <tr>
   <?php
      if ($this->table->label == "Settings")
        { $widths = array('200', '200', '200', '600','200','200');
                   $i = 0;
                   foreach($this->headings as $heading){?>
                <th width="<?php echo $widths[$i];?>px"><?php echo $heading;?></th>
                <?php $i++;}
                 }
      else
        {foreach($this->headings as $heading){?>
    <th><?php echo $heading;?></th>
    <?php }
     }
   ?>
   </tr>

It displayed OK but for the table whose label was "Settings" (the one I was experimenting with) I found the column widths were not affected at all by my change. If you have any suggestions I'd be glad to receive them :)
 
Also tried this ...

Code:
<tr>
   <?php
      if ($this->table->label == "Settings")
        { $widths = array(20, 20, 20, 50, 20, 20);
                   $i = 0;
                   foreach($this->headings as $heading){?>
                <th><?php echo str_pad($heading, $widths[i]);?></th>
                <?php $i++;}
                 }
      else
        {foreach($this->headings as $heading){?>
    <th><?php echo $heading;?></th>
    <?php }
     }
   ?>
   </tr>

Again, it displayed OK but didn't seem to impact column display widths.
 
I would have to see the table to see what the issue is, any possibility of posting a link?

Rob
 
hi

You would have to create a custom table template to do this:
copy views/table/tmpl/default

edit template.php in the copied folder

replace

Code:
<tr>
            <?php foreach($this->headings as $heading){?>
                <th><?php echo $heading;?></th>
                <?php }?>
            </tr>

with

Code:
<tr>
            <?php 
 $widths = array('100', '200', '400');
$i = 0;
foreach($this->headings as $heading){?>
                <th width="<?php echo $widths[$i];?>px"><?php echo $heading[0];?></th>
                <?php $i++;
}?>
            </tr>

replace $widths = array('100', '200', '400'); with a set of values that you want for each of your headings

As far as 2.0 goes - its beta - so not stable. There are less and less bugs each day but you would need to keep up with the svn, and i wouldnt use it on a live site. Oh and the upgrader is yet to be written to migrate from 1 to 2.

cheers
Rob
I used this solution and it worked great for me but now my column labels are only 1 character. Any idea what happened?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top