PHP code example of alanzhaonys / cellbrush
1. Go to this page and download the library: Download alanzhaonys/cellbrush library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alanzhaonys / cellbrush example snippets
$table = \AlanZhao\Cellbrush\Table\Table::create()
->addRowNames(['row0', 'row1', 'row2'])
->addColNames(['col0', 'col1', 'col2'])
->td('row0', 'col0', 'Diag 0')
->td('row1', 'col1', 'Diag 1')
->td('row2', 'col2', 'Diag 2')
;
$html = $table->render();
$table = ...
$table->thead()
->addRowName('head row')
->th('head row', 'col0', 'H0')
->th('head row', 'col1', 'H1')
->th('head row', 'col2', 'H2')
;
$html = $table->render();
$table->td('row0', 'col0', 'Cell contents');
$table->tbody()->td('row0', 'col0', 'Cell contents');
$table->tbody('tb1')
->addRowName(..)
->td(..)
$table->thead()
->addRowName('head row')
->td('head row', '', 'Horizontal cell in thead.')
;
$table
->...
->td('', 'col1', 'Vertical cell')
;
$table->addColNames(['legend', 'products.a', 'products.b', 'products.c']);
$table->thead()
->addRowName('head')
->th('head', 'legend', 'Legend')
// The "Products" label will span 3 columns: products.a, products.b, products.c
->th('head', 'products', 'Products')
->addRowName('name')
->th('name', 'legend', 'Product name')
->th('name', 'products.a', 'Product A')
->th('name', 'products.b', 'Product B')
->th('name', 'products.c', 'Product C')
;
$table
->addRowName('width')
->th('width', 'legend', 'Width')
->td('width', 'products.a', '55 cm')
->td('width', 'products.b', '102 cm')
..
->addRowName('height')
..
->addRowName('price')
->td('price', 'products.a', '7.66 EUR')
$table = Table::create()
->addColNames(['legend', 'sublegend', 0, 1])
->addRowNames(['dimensions.width', 'dimensions.height', 'price'])
->th('dimensions', 'legend', 'Dimensions')
->th('dimensions.width', 'sublegend', 'Width')
->th('dimensions.height', 'sublegend', 'Height')
->th('price', 'legend', 'Price')
;
$table->headRow()->thMultiple(['Product 0', 'Product 1']);
$table->rowHandle('dimensions.width')->tdMultiple(['2cm', '5cm']);
$table->rowHandle('dimensions.height')->tdMultiple(['14g', '22g']);
$table->rowHandle('price')->tdMultiple(['7,- EUR', '5,22 EUR']);
$table = (new Table())
// Add columns.
->addColName('name')
->addColNames(['info.color', 'info.price'])
// Add banana row group.
->addRowNames(['banana.description', 'banana.info'])
->th('banana', 'name', 'Banana')
->td('banana.description', 'info', 'A yellow fruit.')
->td('banana.info', 'info.color', 'yellow')
->td('banana.info', 'info.price', '60 cent')
;
// Alternative syntax with handles, see "Shortcut syntax" below.
$table->addRow('coconut')->th('name', 'Coconut');
$table->addRow('coconut.description')->td('info', 'Has liquid inside.');
$table->addRow('coconut.info')
->td('info.color', 'brown')
->td('info.price', '3 dollar')
;
$table->headRow()
->th('name', 'Name')
->th('info.color', 'Color')
->th('info.price', 'Price')
;
$table = Table::create()
->addRowNames(['T', 'B.T', 'B.B.T', 'B.B.B'])
->addColNames(['L', 'R.L', 'R.R.L', 'R.R.R'])
->td('T', '', 'top')
->td('B', 'L', 'bottom left')
->td('B.T', 'R', 'B.T / R')
->td('B.B', 'R.L', 'B.B / R.L')
->td('B.B.T', 'R.R', 'B.B.T / R.R')
->td('B.B.B', 'R.R.L', 'B.B.B / R.R.L')
->td('B.B.B', 'R.R.R', 'B.B.B / R.R.R')
;
$table = (new Table())->addColNames([0, 1, 2, 3, 4, 5, 6, 7]);
$table->addRow(0)->tdMultiple([0, 1, 2, 3, 4, 5, 6, 7]);
$table->addRow(1)
->tdOpenEnd(0, '0..2')
->tdOpenEnd(3, '3..4')
->tdOpenEnd(5, '5')
->tdOpenEnd(6, '6..7')
;
$table->addRow(2)
->tdOpenEnd(0, '0..1')
->tdOpenEnd(2, '2..3')
->tdOpenEnd(4, '4..6')
->tdOpenEnd(7, '7')
;
$table = (new Table())
->addRowNames(['row0', 'row1', 'row2'])
->addColNames(['legend', 'col0', 'col1', 'col2'])
...
;
// Add cells in a "head0" row in the thead section.
$table->headRow()
->th('col0', 'Column 0')
->th('col1', 'Column 1')
->th('col2', 'Column 2')
;
// Add cells in a "legend" column.
$table->colHandle('legend')
->th('row0', 'Row 0')
->th('row1', 'Row 1')
->th('row2', 'Row 2')
;
$table->addRowClass('row0', 'rowClass0');
// Odd/even zebra striping.
$table->addRowStriping();
// 3-way striping.
$table->addRowStriping(['1of3', '2of3', '3of3']);
$table->addColClass('col0', 'allSectionsColumn0');
$table->tbody()->addColClass('col0', 'tbodyColumn0');
$table->addCellClass('row0', 'col0', 'my_class');
// Create a table, and render it.
$table = Table::create()
->addRowNames(['row0', 'row1', 'row2'])
->addColNames(['col0', 'col1', 'col2'])
->td('row0', 'col0', 'Diag 0')
->td('row1', 'col1', 'Diag 1')
->td('row2', 'col2', 'Diag 2')
;
print $table->render();
// Reorder the columns, and render again.
$table->setColOrder(['col1', 'col2', 'col0']);
print $table->render();