DataTable

DataTable implements OutputableInterface

DataTable

The minimum components of a simple table are some columns and a DataSet (actions are optional).

The ->toDataSet() method can be called on any $result from a PDO query, and doesn’t require QueryCriteria.

The ->addColumn($name, $title) method will grab array values by $name. Otherwise, if you need to display different types of data, call ->format() with a callable function ($row) {} or a Format::using() method.

<?php
$table = DataTable::create('rollGroups');

$table->addColumn('name', __('Name'));
$table->addColumn('tutors', __('Form Tutors'))
      ->format(Format::using('nameList', ['Staff', true, true]));
$table->addColumn('space', __('Room'));
$table->addColumn('students', __('Students'));
$table->addColumn('website', __('Website'))
      ->format(Format::using('link', 'website'));

$actions = $table->addActionColumn()->addParam('gibbonRollGroupID');
$actions->addAction('view', __('View'))
        ->setURL('/modules/Roll Groups/rollGroups_details.php');

echo $table->render($result->toDataSet());
Edit this example

Methods

__construct

Create a data table with optional renderer.

DataTable::__construct( string $id, \Gibbon\Tables\Renderer\RendererInterface $renderer = null )

create

Static create method, for ease of method chaining. Defaults to a simple table renderer.

static DataTable::create( string $id, \Gibbon\Tables\Renderer\RendererInterface $renderer = null ): self

Returns Self: This method can be chained.


createPaginated

Helper method to create a default paginated data table, using criteria from a gateway query.

static DataTable::createPaginated( string $id, \Gibbon\Domain\QueryCriteria $criteria ): self

Returns Self: This method can be chained.


setID

Set the table ID.

DataTable::setID( string $id ): self

Returns Self: This method can be chained.


getID

Get the table ID.

DataTable::getID( ): string

Return Value: string


withData

Set the table data internally.

DataTable::withData( \Gibbon\Domain\DataSet $data ): self

Returns Self: This method can be chained.


setRenderer

Set the renderer for the data table. Can also be supplied ad hoc in the render method.

DataTable::setRenderer( \Gibbon\Tables\Renderer\RendererInterface $renderer ): self

Returns Self: This method can be chained.


getRenderer

Get the current data table renderer.

DataTable::getRenderer( ): \Gibbon\Tables\Renderer\RendererInterface

Return Value: \Gibbon\Tables\Renderer\RendererInterface


addColumn

Add a column to the table, by name and optional label. Returns the created column.

DataTable::addColumn( $id, string $label = '' ): \Gibbon\Tables\Columns\Column

Return Value: \Gibbon\Tables\Columns\Column


addActionColumn

Add an action column to the table, which is generally rendered on the right-hand side.

DataTable::addActionColumn( ): \Gibbon\Tables\Columns\ActionColumn

Return Value: \Gibbon\Tables\Columns\ActionColumn


addCheckboxColumn

Add a checkbox column to the table, used for bulk-action tables.

DataTable::addCheckboxColumn( $id, $key = '' ): \Gibbon\Tables\Columns\CheckboxColumn

Return Value: \Gibbon\Tables\Columns\CheckboxColumn


addExpandableColumn

Add an expander arrow for

DataTable::addExpandableColumn( $id ): \Gibbon\Tables\Columns\ExpandableColumn

Return Value: \Gibbon\Tables\Columns\ExpandableColumn


getColumns

Get all columns in the table.

DataTable::getColumns( ): array

Return Value: array


getColumnCount

Count all columns in the table.

DataTable::getColumnCount( ): integer

Return Value: integer


addHeaderAction

Add an action to the table, generally displayed in the header right-hand side.

DataTable::addHeaderAction( string $name, string $label = '' ): \Gibbon\Tables\Action

Return Value: \Gibbon\Tables\Action


getHeader

Get all header content in the table.

DataTable::getHeader( ): array

Return Value: array


addMetaData

Add a piece of meta data to the table. Can be used for renderer-specific details.

DataTable::addMetaData( string $name, mixed $value ): self

Returns Self: This method can be chained.


getMetaData

Gets the value of a meta data entry by name.

DataTable::getMetaData( string $name, $defaultValue = null ): mixed

Return Value: mixed


modifyRows

Add a callable function that can modify each row based on that row’s data.

DataTable::modifyRows( callable $callable ): self

Returns Self: This method can be chained.


getRowModifiers

Get the row logic array of callables.

DataTable::getRowModifiers( ): array

Return Value: array


render

Render the data table, either with the supplied renderer or default to the built-in one.

DataTable::render( \Gibbon\Domain\DataSet $dataSet, \Gibbon\Tables\Renderer\RendererInterface $renderer = null ): string

Return Value: string


getOutput

Implement the OutputtableInterface to combine DataTables + Forms.

DataTable::getOutput( ): string

Return Value: string


Last updated : September 15, 2018 b92362d