Table Columns and Formatters

class atk4\ui\TableColumn\Generic

Generic description of a column for atk4\ui\Table

Table object relies on a separate class: atk4uiTableColumnGeneric to present most of the values. The goals of the column object is to format anything around the actual values. The type = ‘money’ will result in a custom formatting of the value, but will also require column to be right-aligned. To simplify this, type = ‘money’ will use a different column class - TableColumnMoney. There are several others, but first we need to look at the generic column and understand it’s base capabilities:

A class resposnible for cell formatting. This class defines 3 main methods that is used by the Table when constructing HTML:

atk4\ui\TableColumn\Generic::getHeaderCellHTML(atk4dataField $f)

Must respond with HTML for the header cell (<th>) and an appropriate caption. If necessary will include “sorting” icons or any other controls that go in the header of the table.

atk4\ui\TableColumn\Generic::getTotalsCellHTML(atk4dataField $f, $value)

Provided with the field and the value, format the cell for the footer “totals” row. Table can rely on various strategies for calculating totals. See Table::addTotals.

atk4\ui\TableColumn\Generic::getDataCellHTML(atk4dataField f)

Provided with a field, this method will respond with HTML template. In order to keep performance of Web Application at the maximum, Table will execute getDataCellHTML for all the fields once. When iterating, a combined template will be used to display the values.

The template must not incorporate field values (simply because related model will not be loaded just yet), but instead should resort to tags and syntax compatible with Template.

A sample template could be:


Note that the “name” here must correspond with the field name inside the Model. You may use multiple field names to format the column:


The above 3 methods define first argument as a field, however it’s possible to define column without a physical field. This makes sense for situations when column contains multiple field values or if it doesn’t contain any values at all.

Sometimes you do want to inject HTML instead of using row values:

atk4\ui\TableColumn\Generic::getHTMLTags($model, $field = null)

Return array of HTML tags that will be injected into the row template. See Injecting HTML for further example.

class atk4\ui\TableColumn\Actions

Can be used to add “action” column to your table:

$action = $table->addColumn(null, 'Actions');

If you want to have label above the action column, then:

$action = $table->addColumn(null, ['Actions', 'caption'=>'User Actions']);

See also atk4uiGrid::addAction()

atk4\ui\TableColumn\Actions::addAction($button, $action, $confirm = false)

Adds another button into “Actions” column which will perform a certain JavaScript action when clicked. See also atk4uiGrid::addAction()

atk4\ui\TableColumn\Actions::addModal($button, $title, $callback)

Triggers a modal dialog when you click on the button. See description on atk4uiGrid::addModalAction()