Download the PHP package alanzhaonys/cellbrush without Composer
On this page you can find all versions of the php package alanzhaonys/cellbrush. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alanzhaonys/cellbrush
More information about alanzhaonys/cellbrush
Files in alanzhaonys/cellbrush
Package cellbrush
Short Description Library to generate HTML tables.
License MIT
Homepage http://github.com/donquixote/cellbrush
Informations about the package cellbrush
Cellbrush table generator
A library to generate HTML tables with PHP.
Table structure:
- Named rows and columns, so they can be targeted with string keys.
- Colspan and rowspan using col groups and row groups.
- Automatically fills up empty cells, to preserve the structural integrity.
- Automatically warns on cell collisions.
Tag attributes:
- Easily add row classes.
- Easily add row striping classes (odd/even zebra striping and more).
- Easily add column classes that apply to all cells in the column.
- (more planned)
API design:
- Method chaining instead of huge arrays of doom.
- Shortcut notations for frequently used stuff.
- Return value and parameter types nicely documented, so your IDE can let you know about possible operations.
- Exceptions thrown for integrity violation.
- Composer and PSR-4.
Basic usage
A simple 3x3 table with the diagonal cells filled.
Diag 0 | ||
Diag 1 | ||
Diag 2 |
Too verbose? Look for "Shortcut syntax" below.
Cells in thead and tfoot
A table like above, but with added thead section.
Column names are shared between table sections, but new rows need to be defined for each section.
H0 | H1 | H2 |
---|---|---|
Diag 0 | ||
Diag 1 | ||
Diag 2 |
Additional tbody sections
By default, every addRowName() and td() or th() goes into the main tbody section.
So, the following two are equivalent:
More named tbody sections can be added like this:
Again, the column definitions are shared between table sections, but row definitions need to be added separately.
Full rowspan and colspan
To let a cell span the entire width of the table, simply set the column name to ''. Likewise, set the row name to '' to span the entire height of the table section.
Horizontal cell in thead. | ||
# | Vertical cell | # |
# | # | |
# | # |
Column groups
Named column groups allow for cells with colspan. In the below example, the column name "products" specifies a colspan cell that spans all 3 products.* cells, whereas "products.a", "products.b" and "products.c" specifies specific cells without colspan.
Legend | Products | ||
---|---|---|---|
Product name | Product A | Product B | Product C |
Width | 55 cm | 102 cm | 7 cm |
Row groups
Similar to column groups.
Product 0 | Product 1 | ||
---|---|---|---|
Dimensions | Width | 2cm | 5cm |
Height | 14g | 22g | |
Price | 7,- EUR | 5,22 EUR |
Combination of row groups and column groups
Name | Color | Price |
---|---|---|
Banana | A yellow fruit. | |
yellow | 60 cent | |
Coconut | Has liquid inside. | |
brown | 3 dollar |
Nested groups
Groups can have unlimited depth.
top | |||
bottom left | B.T / R | ||
B.B / R.L | B.B.T / R.R | ||
B.B.B / R.R.L | B.B.B / R.R.R |
Open-ended cells
Open-end cells allow overlapping colspan cells, like bricks in a wall.
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
0..2 | 3..4 | 5 | 6..7 | ||||
0..1 | 2..3 | 4..6 | 7 |
Shortcut syntax with row handles and column handles
RowHandle and *ColHandle allow you to omit one of $rowName and $colName to address a table cell.
Column 0 | Column 1 | Column 2 | |
---|---|---|---|
Row 0 | Diag 0 | ||
Row 1 | Diag 1 | ||
Row 2 | Diag 2 |
Row classes
Row classes can be added quite easily with addRowClass()
.
Row striping
Row striping classes can be added to a table section with addRowStriping()
.
The default striping is ['odd', 'even']
, but different patterns can be added with three or more stripes.
The striping always applies to a table section. By default, this wil be the main tbody section.
Column classes
You can use addColClass()
to add a class to all cells of a column.
This can be done either for all table sections at once, or for specific table sections.
Cell classes
Use addCellClass()
to add classes to individual cells.
Column Reordering
Columns can be reordered even after the cells are already added.
Diag 0 | ||
Diag 1 | ||
Diag 2 |
Diag 0 | ||
Diag 1 | ||
Diag 2 |
More examples?
You can see more examples in the unit tests.
Planned features
Next steps:
- Collision detection.
- Dedicated exception classes.