3.2.0

Auto Column Widths using MySQL/PHP

Here's MySQL/PHP code that you can slot in right prior to echo activewidgets_grid($name, $data);

The only variable you should have to control is $data. $data should be the resulting recordset from mysql_query() command.

I have a $min_col_length variable that you can set, which will allow you to play with the widths a little more. It will prevent columns with very small data lengths from fouling up the headers, as well as giving the columns a much nicer flow.

// dynamic column width
    $records = mysql_numrows($data);

    for($i=0; $i < $records; $i++) {
      $row = mysql_fetch_row($data);
      $length = mysql_fetch_lengths($data);
      foreach($length as $key => $value) {if($maxlength[$key] < $value) {$maxlength[$key] = $value;} }
    }

    mysql_data_seek($data,0);

    $min_col_length = 30;

    print "<style>";
        foreach($maxlength as $key => $value) {if($value * 10 < $min_col_length) {print".active-column-$key {width:" . ($min_col_length) . "px}";} else {print".active-column-$key {width:" . ($value * 10) . "px}";}}
    print "</style>";
BMW
January 10,
Try something like this instead

<script>
if (isIE)
{
wdth = document.body.clientWidth;
}
else
{
wdth = document.documentElement.clientWidth;
}

var stylesheet = document.styleSheets[document.styleSheets.length-1];
var cwdth = wdth - 30 - 18;

if (isIE)
{
<?php foreach($cols_widths as $k=>$perc) {?>
stylesheet.addRule(".aw-column-<?php echo $k?>", "width:"+parseInt(cwdth*<?php echo $perc;?>/100 )+"px"+";text-align: <?php echo $cols_align[$k]?>;");
<?php } ?>
}
else
{
var gs = document.getElementById('gridstyle').sheet;
<?php foreach($cols_widths as $k=>$perc) {?>
gs.insertRule(".aw-column-<?php echo $k?>{ width:"+parseInt(cwdth*<?php echo $perc;?>/100 )+"px"+";text-align: <?php echo $cols_align[$k]?>;"+"}", gs.cssRules.length );
<?php } ?>
}
Bogdan
January 11,

This topic is archived.

See also:


Back to support forum