HOME   SITEMAP   CONTACT   NEWS   BLOG
Search


Framework HTML Table Class


Can manipulate content, attributes and styles and then render the data to a nicely formed HTML table.
  • push in rows and columns anywhere, overwrite values...
  • hide rows, columns, areas
  • span rows, columns, areas
  • set or merge html attributes and css styles.
  • can use instances of Bs_HtmlTableWindrose for styling
  • supports multiple-cascaded tables (a cells content can be an instance of Bs_HtmlTable, ...)

This class can be used in conjunction with the Bs_HtmlTableWindrose.

Example:

At first create a data array and set some styles, then render the table using toHtml():

<?php
require_once($APP['path']['core']      . 'html/table/Bs_HtmlTable.class.php');
$htmlTable_0 =& new Bs_HtmlTable();
$htmlTable_1 =& new Bs_HtmlTable();

// Make a content matrix
$dataMatrix_0 = array(&$htmlTable_1);

$dataMatrix_1 = array(
  array(
'apple'''      ''),
  array(
'grape''orange''pear'),
  array(
'plum' ''      '')
);

// Init tables with data
$htmlTable_0->initByMatrix($dataMatrix_0);
$htmlTable_1->initByMatrix($dataMatrix_1);

$htmlTable_1->setTableAttr(array('BORDER'=>'0''CELLPADDING'=>'2''CELLSPACING'=>'1'));
$htmlTable_1->setTrAttr(0, array('ALIGN'=>'right'));
$htmlTable_1->setTdAttr(00, array('CLASS'=>'header''COLSPAN'=>'3'));
$htmlTable_1->setTdStyle(00, array('color'=>'red''font'=>'italic 18pt sans-serif'));
$htmlTable_1->setTdAttr(10, array('WIDTH'=>'100''BGCOLOR'=>'#cccccc'));
$htmlTable_1->setTdStyle(10, array('font'=>'bold 9pt monospace'));
$htmlTable_1->setTdAttr(11, array('WIDTH'=>'100''BGCOLOR'=>'#cccccc'));
$htmlTable_1->setTdStyle(11, array('font'=>'18pt monospace'));
$htmlTable_1->setTdAttr(12, array('WIDTH'=>'100''BGCOLOR'=>'#cccccc''ROWSPAN'=>'2'));
$htmlTable_1->setTdStyle(12, array('background'=>'red'));
$htmlTable_1->setTdAttr(20, array('ALIGN'=>'right''BGCOLOR'=>'blue''COLSPAN'=>'2'));
$htmlTable_1->setTdStyle(20, array('color'=>'white''font'=>'bold 18pt serif'));

// Init tables with attributes
$htmlTable_0->setTableAttr(array('CELLSPACING'=>'0''CELLPADDING'=>'0''BORDER'=>'8''BORDERCOLOR'=>'red'));
$htmlTable_0->setTdAttr(00, array('BGCOLOR'=>'green'));

echo 
$htmlTable_0->toHtml();
?>

And this is how it looks:


Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /usr/local/lib/php/blueshoes-4.6/core/html/table/Bs_HtmlTable.class.php on line 690
apple    
grape orange pear
plum    


Now we are doing some modifications (pushRow(), pushCol() and setRowStyle()) and render the table again:

<?php
$htmlTable_1
->pushRow(array(1,2,3), 2);
$htmlTable_1->pushCol(array(1,2,3,4), 2);
$htmlTable_1->setRowStyle(2,array('color'=>'lightblue''font'=>'bold 18pt serif'));
echo 
$htmlTable_0->toHtml();
?>

And this is how it looks:

apple   1  
grape orange 2 pear
1 2 3 3
plum   4  


Documentation:

  • Check out the API-Doc for this class.

Download:

This class ships with the BlueShoes Framework. See the download page.


Let us know

Have you done something interesting with BlueShoes or one of its components?