PHPackages                             jmasci/html-table - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jmasci/html-table

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jmasci/html-table
=================

flexible HTML table rendering class using git://j-masci/component-template

017PHP

Since Jan 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/j-masci/html-table)[ Packagist](https://packagist.org/packages/jmasci/html-table)[ RSS](/packages/jmasci-html-table/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

### Usage

[](#usage)

```
use JMasci\HtmlTable\Table;
use JMasci\HtmlTable\TemplateFactory;

// map of column indexes to column labels. Use null to infer from first row of data.
$cols = null;

// an array of arrays, or an array of stdClass objects.
$rows = $db->query( "SELECT * FROM some_table" );

// optional table arguments.
$args = [];

// inject a pre-built rendering template or build your own template to inject.
// in many projects you'll find it useful to create your own template or extend the default one to
// inject project-specific behaviour.
$template = TemplateFactory::default();

// "extend" the template for this instance only, by overriding one of the components.
$template->set( 'td', function($table, $row_index, $col_index ){

    // raw cell value that was passed into the table object.
    $raw_value = @$table->rows[$row_index][$col_index];

    // table args are accessible here
    if ( @$table->args['option'] ) {
        // do something differently
    }

    // this templates components all output their HTML. Your own template may decide to return
    // it instead.
    ?>
    ...
