List

The listing array defines how records are listed. The Contao core engine supports three different “list view”, “parent view” and “tree view”. You can configure various sorting options like filters or the default sorting order and you can add custom labels.

Sorting

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['sorting'] = [
    // …
];
KeyValueDescription
modeSorting mode (integer)0 Records are not sorted
1 Records are sorted by a fixed field
2 Records are sorted by a switchable field
3 Records are sorted by the parent table
4 Displays the child records of a parent record (see style sheets module)
5 Records are displayed as tree (see site structure)
6 Displays the child records within a tree structure (see articles module)

Note: Before Contao 4.13 you will need to implement a child_record_callback in mode 4, otherwise no records will be shown in backend.
flagSorting flag (integer)1 Sort by initial letter ascending
2 Sort by initial letter descending
3 Sort by initial two letters ascending
4 Sort by initial two letters descending
5 Sort by day ascending
6 Sort by day descending
7 Sort by month ascending
8 Sort by month descending
9 Sort by year ascending
10 Sort by year descending
11 Sort ascending
12 Sort descending
panelLayoutPanel layout (string)search show the search records menu
sort show the sort records menu
filter show the filter records menu
limit show the limit records menu.
Separate options with comma (= space) and semicolon (= new line) like sort,filter;search,limit.
fieldsDefault sorting values (array)One or more fields that are used to sort the table.
headerFieldsHeader fields (array)One or more fields that will be shown in the header element (sorting mode 4 only).
iconTree icon (string)Path to an icon that will be shown on top of the tree (sorting mode 5 and 6 only).
rootRoot nodes (array)IDs of the root records (pagemounts). This value usually takes care of itself.
rootPastetrue/false (bool)Enable paste buttons at root level. (default: false)
filterQuery filter (array)Allows you to add custom filters as arrays, e.g. [['status=?', 'active'], ['usages>?', 0]].
disableGroupingtrue/false (bool)Allows you to disable the group headers in list view and parent view.
defaultSearchFieldField name (string)since 5.1 Set a default search field for the search records menu instead of selecting the alphabetically first field.
paste_button_callbackCallback function (array)These functions will be called instead of displaying the default paste buttons. Please specify as ['Class', 'Method'] or use an anonymous function.
child_record_callbackCallback function (array)These functions must be specified to render the child elements (sorting mode 4 only). Please specify as ['Class', 'Method'] or use an anonymous function.
header_callbackCallback function (array)These functions will be called when the header fields (sorting mode 4 only) are created. Please specify as ['Class', 'Method'] or use an anonymous function.
panel_callbackCallback function (array)This callback allows you to inject HTML for custom panels. Please specify as ['Class', 'Method'] or use an anonymous function.
child_record_classCSS class (string)Allows you to add a CSS class to the parent view elements.

since 4.13 The Contao\DataContainer class provides constants for the various sorting modes and flags, e.g.

// Displays the child records of a parent record (see content elements)
'mode' => Contao\DataContainer::MODE_PARENT, // 4

// Records are displayed as tree (see site structure)
'mode' => Contao\DataContainer::MODE_TREE, // 5

//Sort by initial letter ascending
'flag' => Contao\DataContainer::SORT_INITIAL_LETTER_ASC, // 1

// Sort by initial letter descending
'flag' => Contao\DataContainer::SORT_INITIAL_LETTER_DESC, // 2

Labels

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['label'] = [
    // …
];
KeyValueDescription
fieldsFields (array)One or more fields that will be shown in the list (e.g. ['title', 'user_id:tl_user.name']).
showColumnstrue/false (bool)If true Contao will generate a table header with column names (e.g. back end member list)
showFirstOrderBytrue/false (bool)since 4.13.36 If false Contao will not force the first sorting field to show up in the list.
formatFormat string (string)HTML string used to format the fields that will be shown (e.g. '%s (%s)').
maxCharactersNumber of characters (integer)Maximum number of characters of the label.
group_callbackCallback functions (array)Call a custom function instead of using the default group header function.
label_callbackCallback functions (array)Call a custom function instead of using the default label function.

Operations

The operations are divided into two sections: global operations that relate to all records at once (e.g. editing multiple records) and regular operations that relate to a particular record only (e.g. editing or deleting a record).

Global operations

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['global_operations'] = [
    // …
];
KeyValueDescription
label&$GLOBALS['TL_LANG'] (string)Button label. Typically a reference to the global language array.
hrefURL fragment (string)URL fragment that is added to the URI string when the button is clicked (e.g. act=editAll).
iconIcon (string)Path and filename of the icon.
classCSS class (string)CSS class attribute of the button.
attributesAdditional attributes (string)Additional attributes like event handler or style definitions.
button_callbackCallback function (array)Call a custom function to generate the button. Please specify as ['Class', 'Method'] or use service tagging.

This feature is available in Contao 4.7 and later.

KeyValueDescription
routeSymfony Route Name (string)The button will redirect to the given Symfony route.

since 5.3 You do not have to define any settings for global operations anymore. Instead, you can give a list of which operations should be available for your data container.

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['global_operations'] = [
    'all',
    'toggleNodes',
];

Regular operations

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['operations'] = [
    // …
];
KeyValueDescription
label&$GLOBALS['TL_LANG'] (string)Button label. Typically a reference to the global language array.
hrefURL fragment (string)URL fragment that is added to the URI string when the button is clicked (e.g. act=edit).
iconIcon (string)Path and filename of the icon.
attributesAdditional attributes (string)Additional attributes like event handler or style definitions.
button_callbackCallback function (array)Call a custom function to generate the button. Please specify as ['Class', 'Method'] or use service tagging.
showInHeadertrue/false (bool)since 4.5 Shows the operation in the header element (sorting mode 4 only).
routeSymfony Route Name (string)since 4.7 The button will redirect to the given Symfony route.

since 5.0 You do not have to define any settings for standard operations anymore. Instead, you can give a list of which operations should be available for your data container. Contao will also check the appropriate contao_dc.<data-container> permission for these operations.

// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example']['list']['operations'] = [
    'edit',
    'children',
    'copy',
    'cut',
    'delete',
    'toggle',
    'show',
];

Toggle Operation

since 5.0 You can implement an automatic toggle operation for data containers that contain a boolean field. This is typically used for fields that control a “published” state of a data record for example, but the use case can be arbitrary.

// contao/dca/tl_foobar.php
$GLOBALS['TL_DCA']['tl_foobar']['list']['operations'][] = 'toggle';

$GLOBALS['TL_DCA']['tl_foobar']['fields']['published'] = [
    'toggle' => true,
    'inputType' => 'checkbox',
    'sql' => ['type' => 'boolean', 'default' => false],
];

If the state of your field is reversed you can instead define reverseToggle:

$GLOBALS['TL_DCA']['tl_foobar']['fields']['invisible'] = [
    'reverseToggle' => true,
    'inputType' => 'checkbox',
    'sql' => ['type' => 'boolean', 'default' => false],
];