PHP code example of tlr / html-table-builder

1. Go to this page and download the library: Download tlr/html-table-builder 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/ */

    

tlr / html-table-builder example snippets


use Tlr\Tables\Elements\Table;

$table = new Table;

$table->class('ui celled table');

$row = $table->header()->row();
$row->cell('Name');
$row->cell('Age');
$row->cell('Something Else');

$row = $table->body()->row();

$row->cell('George');
$row->cell('12');
$row->cell('Food');

$table->footer()->row()
    ->cell('<a href="/create">Add a new entry</a>')->dontEscape()->span(3);

echo $table->render();

(new TableRenderer)->renderElement($table);

(new TableRenderer)->prettyPrint()->renderElement($table);


$one = $section->row();
$two = $section->row();

$section->nextRow($one) === $two; // true
$section->nextRow($two); // a new row

$row->cell('Cat'); // <td>Cat</td>
$row->cell('<Cat>'); // <td>&lt;Cat&gt;</td>
$row->cell('<Cat>')->raw(); // <td><Cat></td>
$row->cell()->content('Cat'); // <td>Cat</td>
$row->cell()->wrapContent('<strong>', '<Cat>', '</strong>'); // <strong>&lt;Cat&gt;</strong>

$row->linkCell('https://google.com')->content('Visit Google.');
// <td><a href="https://google.com">Visit Google.</a></td>

$cell = new LinkCell('localhost')->content('<pre>some preformatted text</pre>')->raw();

$row->imageCell('cat.jpg');
// <td><img src="cat.jpg" /></td>

// setting rowspan
$row->cell('A double height column')->spanRows(2);

// setting colspan
$row->cell('A triple width column')->spanColumns(3);

// This is the semantic ui CSS framework table class
$table->class('ui table');

// You don't have to set the classes at the same time.
$table->class('ui')->class('table');

// You can pass an array of string
$table->class(['ui', 'table']);

$table->attribute('foo', 'bar');