Fork me on GitHub

Mesour Table

Easy way to create HTML table in PHP

Packagist

  • None

Installation

Suggests

  • None

Demo

Method Parameters Returns Description
setName $name Mesour\Table\Column Set column name.
setHeader $header Mesour\Table\Column Set header text.
setCallback $callback Mesour\Table\Column Set render callback.

Initializing

$table = new \Mesour\UI\Table();

$data = array(
    array(
        'method' => 'setName',
        'params' => '$name',
        'returns' => 'Mesour\Table\Column',
        'description' => 'Set column name.',
    ),
    array(
        'method' => 'setHeader',
        'params' => '$header',
        'returns' => 'Mesour\Table\Column',
        'description' => 'Set header text.',
    ),
    array(
        'method' => 'setCallback',
        'params' => '$callback',
        'returns' => 'Mesour\Table\Column',
        'description' => 'Set render callback.',
    )
);

$table->setSource($data);

$table->setAttribute('class', 'table table-striped table-hover');

$table->addColumn('method', 'Method')
    ->setCallback(function($data) {
        return \Mesour\Components\Html::el('b')->setText($data['method']);
    });

$table->addColumn('params', 'Parameters');

$table->addColumn('returns', 'Returns');

$table->addColumn('description', 'Description');

echo $table->render();

Output

<table class="table table-striped table-hover">
    <thead>
        <tr>
            <th>Method</th>
            <th>Parameters</th>
            <th>Returns</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><b>setName</b></td>
            <td>$name</td>
            <td>Mesour\Table\Column</td>
            <td>Set column name.</td>
        </tr>
        <tr>
            <td><b>setHeader</b></td>
            <td>$header</td>
            <td>Mesour\Table\Column</td>
            <td>Set header text.</td>
        </tr>
        <tr>
            <td><b>setCallback</b></td>
            <td>$callback</td>
            <td>Mesour\Table\Column</td>
            <td>Set render callback.</td>
        </tr>
    </tbody>
</table>