Columns - Jet\DataListing_Column

Each usage column in the data list must be represented by its own class, which must inherit from this abstract class.

The column definition allows the following:

  • Uniquely identify the column - each column should have its own unique key.
  • Generate a caption and possibly a column icon.
  • Specifies whether the column is/is not visible.
  • It is possible to specify the order of the columns.
  • It is possible to specify whether the column allows/does not allow sorting.
  • Generate sorting for ORM.
  • Automatic generation of the UI_dataGrid column with the possibility of adding your own optional initialization.
  • Data generation for export.

Data cell view

Each column has its own view rendering the data cells of the list (specific column, specific row). For example, a view cell can take the following form:

namespace JetApplicationModule\EventViewer\Admin;

use 
Jet\MVC_View;
use 
JetApplication\Logger_Admin_Event as Event;

/**
 * @var MVC_View $this
 * @var Event    $item
 * @var Listing  $listing
 */
$item $this->getRaw'item' );
$listing $this->getRaw'listing' );
?>
<a href="<?=$listing->getItemURI($item->getId())?>"><?=$item->getEvent();?></a>

The name of the view script must match the column identification key. So in our example it is event.phtml.

Method Overview

Method Meaning of
public setListing(
DataListing $listing
) : void
The list automatically sets the column reference to itself when a column is passed. This method is used for this purpose.
public getListing(
) : DataListing
Returns the instance of the data list to which the column belongs.
abstract public getKey(
) : string
Returns a unique key identifying the column. It is recommended to implement as follows: class Listing_Column_Event extends DataListing_Column
{
    public const 
KEY 'event';
    
    public function 
getKey(): string
    
{
        return static::
KEY;
    }
}
And then work with the column as follows: $this->listing->columnListing_Column_Event::KEY )->setIsVisiblefalse );
abstract public getTitle(
) : string
Returns the generated and possibly already translated column header.
public getIcon(
) : string
Can return the name of the column icon. Optional.
public getIsVisible(
) : bool
Indicates whether the column is/is not visible.
public setIsVisible(
bool $is_visible
) : void
Sets whether the column is/is not visible.
public getIndex(
) : int
Returns the column order by which the skins will be sorted.
public setIndex(
int $index
) : void
Sets the column order by which the peels will be sorted.
public isMandatory(
) : bool
Specifies whether the column is mandatory. A mandatory column cannot be hidden.
public getDisallowSort(
) : bool
Specifies whether sorting by the given column is disabled.
public getOrderByAsc(
) : array|string
Generates parameters for ascending sorting for ORM.

Default implementation: return '+'.$this->getKey(); However, it is possible to overload e.g. as follows: return ['+some_property''+some_model.some_property'];
public getOrderByDesc(
) : array|string
Generates parameters for descending sorting for ORM.

Default implementation: return '-'.$this->getKey(); However, it is possible to overload e.g. as follows: return ['-some_property''-some_model.some_property'];
public render(
mixed $item
) : string
It takes care of generating the appropriate view script for the list row. The default implementation is as follows: $view $this->listing->getColumnView();
$view->setVar('item'$item);
$view->setVar('listing'$this->listing );
$view->setVar('column'$this );
        
return 
$view->render$this->getKey() );
Which implies:
  • The Jet\MVC_View instance is held by the list instance. The list column only takes it over.
  • The name of the view script in the default implementation corresponds to the column key.
  • The View script has an instance of the item (list row), an instance of the list, and an instance of the column.
public initializer(
UI_dataGrid_column $column
) : void
By overloading this method it is possible to implement a custom initialization of the UI_dataGrid column.
public getExportHeader(
) : null|string|array
Returns the header of the data export. It can return the following values:
  • null: Column will not be exported
  • string: The column will be represented by one column in the export. The value is then the name of the column written in the export (e.g. the column header in the table).
  • array: The column will be represented by multiple columns in the export. Each field value then represents the name listed in the export.
public getExportData(
mixed $item
) : float|int|bool|string|array
It generates data for the given column and the given row ($item parameter) to build the export.

If the getExportHeader method returned an array, then this method must also return the corresponding array.
Previous chapter
Working with data lists - Jet\DataListing
Next chapter
Filters - Jet\DataListing_Filter