Introduction
This article explains main options of ItemsList widget in admin area: how to create Remove and Create buttons, define look of columns, etc.
This guide has two parts:
- The first is about parameters of columns in the ItemsList;
- the second is about parameters of ItemsList itself.
In order to be able to play with settings which will be described below, we recommend installing a simple ItemsList module and try to change it according to options below.
Column parameters
ItemsList columns are defined by the defineColumns()
method, that returns an array of arrays, each of them representing a column. and there are two mandatory fields that must exist in each column:
static::COLUMN_NAME
- value type: string;
- defines the column name that will be displayed in the table's header.
- value type: string;
static::COLUMN_ORDERBY
- value type: integer;
- defines the column position: the greater the value, the lower it will sit.
- value type: integer;
You can also define other parameters for a column:
static::COLUMN_MAIN
- value type: boolean;
- defines whether this is a main column. The main column will soak up all unused space of the ItemsList.
- value type: boolean;
static::COLUMN_SORT
- value type: string;
- defines a sorting option for this column. More info about implementing sorting in ItemsLists.
- value type: string;
static::COLUMN_TEMPLATE
- value type: string, path to a template;
- defines a specific template for displaying column cell. Typical value is like
modules/Developer/Module/tempalte.twig
and it will pick up theskins/admin/modules/Developer/Module/tempalte.twig
template.
- defines a specific template for displaying column cell. Typical value is like
- value type: string, path to a template;
static::COLUMN_HEAD_TEMPLATE
- value type: string, path to a template;
- similarly to above, defines a specific template for displaying head cell of a table.
- value type: string, path to a template;
static::COLUMN_CLASS
- value type: string, name of the class;
- defines a FormField class that will be used for displaying editable field, e.g.
\XLite\View\FormField\Inline\Input\Text\Float
(a field that accepts only float number). If you need more info about creating editable ItemsList in admin area, please have a look at Creating new entity -- Introduction of editable ItemsList in admin area guide.
- defines a FormField class that will be used for displaying editable field, e.g.
- value type: string, name of the class;
static::COLUMN_PARAMS
- value type: array;
- defines parameters for FormField class defined in
static::COLUMN_CLASS
parameter.
- defines parameters for FormField class defined in
- value type: array;
ItemsList parameters
ItemsList parameters are defined as methods in the ItemsList class and the mandatory ones are:
defineRepositoryName()
method that points an ItemsList to a Model class;defineColumns()
method defines what columns exist in this ItemsList.
Aside from these two, you can define:
isSwitchable()
method. If it returnstrue
, it will add enable/disable icon to an ItemsList and this icon will work with$enabled
property of the model class. If you want to change a field that is responsible for this icon, you need to work withgetSwitcherField()
method;isRemoved()
method. If it returnstrue
, ItemsList will have remove icon:isInlineCreation()
method defines whether to show Create button in the ItemsList: This method can returnstatic::CREATE_INLINE_NONE
and the button will not be displayed (default option). If it returnsstatic::CREATE_INLINE_TOP
, then the button will be displayed at the top of the table. If it returnsstatic::CREATE_INLINE_BOTTOM
, then the button will be displayed in the bottom of the table. If you want to change the label for create button, then the desired text should be returned by thegetCreateButtonLabel()
method.getCreateURL()
method is used in conjunction withisInlineCreation()
method and it defines URL of the page where new record will be created. If it is the same page, where your ItemsList sits on, then a new item will be created right in the table without reloading the page. Otherwise, you will be redirected to the page returned by thegetCreateURL()
method. Typical implementation of this method is:protected function getCreateURL()
{
return \XLite\Core\Converter::buildUrl('your_target');
}where your_target is a target of a page.