|
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(0, 0, array('CLASS'=>'header', 'COLSPAN'=>'3')); $htmlTable_1->setTdStyle(0, 0, array('color'=>'red', 'font'=>'italic 18pt sans-serif')); $htmlTable_1->setTdAttr(1, 0, array('WIDTH'=>'100', 'BGCOLOR'=>'#cccccc')); $htmlTable_1->setTdStyle(1, 0, array('font'=>'bold 9pt monospace')); $htmlTable_1->setTdAttr(1, 1, array('WIDTH'=>'100', 'BGCOLOR'=>'#cccccc')); $htmlTable_1->setTdStyle(1, 1, array('font'=>'18pt monospace')); $htmlTable_1->setTdAttr(1, 2, array('WIDTH'=>'100', 'BGCOLOR'=>'#cccccc', 'ROWSPAN'=>'2')); $htmlTable_1->setTdStyle(1, 2, array('background'=>'red')); $htmlTable_1->setTdAttr(2, 0, array('ALIGN'=>'right', 'BGCOLOR'=>'blue', 'COLSPAN'=>'2')); $htmlTable_1->setTdStyle(2, 0, 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(0, 0, 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
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:
|
1 |
|
grape |
orange |
2 |
pear |
1 |
2 |
3 |
3 |
plum |
|
4 |
|
|
|
|
|