Table
The table
tag describes a table, but it's important not to confuse a physical database table with what is described in XML, as an XML table can describe one table that consists of multiple different columns from different database tables. However, in any XML table, there is a main database table, and it is specified by the name
attribute in the table
tag.
Attributes
name
name
is the table identifier. In most cases, it matches the physical name of the main table in the database, but sometimes you need the table name in XML and database to be different. In such cases, use the alias
attribute to specify the physical table name in the database.
name="products"
alias="products_table"
groupBy
In this attribute, you should list the fields by which you want to group, separated by commas.
paging
paging
is used to specify the pagination method for the list of records in the table.
If set to ajax, rows should load dynamically when scrolling through the record list.
If multiple DGS are displayed on one page, it's not recommended to use this for all DGS except the last one.
paging="ajax"
exceptionMode
If exceptionMode equals true, then errors will not be displayed through a dialog, but will throw a StoreException
.
If you need to set exceptionMode for all Stores, you need to pass the option storeExceptionMode = true
to the core.
mode
If mode equals api
, then XML will support RESTful.
onBeforeConnection
Using this attribute, you can influence and change connection parameters. It helps us override the connection in DGS.
<table charset="UTF-8"
name="games"
primaryKey="id"
defaultOrderField="id"
defaultOrderDirection="DESC"
onBeforeConnection="onFacebookConnection"
plugin="Games"
rowsForPage="50">
public function onFacebookConnection(IDataAccessObject &$connection, Store &$store)
{
$connection = DataAccessObject::getInstance('Facebook', $this->core->db);
return true;
}
For example, by implementing the
IDataAccessObject
interface inFacebookObject
, you can override the logic for working with Facebook API or GraphQL
proxy
By default, SQL proxy is used for working with the database.
For API work, use proxy="json"
.
errorMessage
When a storage error occurs, you can specify a standard message to display to the user.
grideditor
When enabled, allows editing cell values in the table by double-clicking on them.
grideditor="true"
When editing, all events from the
Store::ACTION_EDIT
action are available
join
You can specify expressions for join:
<table charset="UTF-8"
name="chats_rooms"
primaryKey="id"
defaultOrderField="id"
defaultOrderDirection="DESC"
rowsForPage="50"
refreshDataTimeout="30"
join="LEFT JOIN chats_rooms2users ON (chats_rooms2users.id_chat_room = chats_rooms.id)"
groupBy="chats_rooms.id">
...
</table>
additionalWhere
You can write additional conditions for data selection. However, it's better not to use this option.
customFrom
If the real table name differs from the DGS name, it should be specified in the customFrom
attribute.
Describing the Model Using an Array
Creating storage doesn't necessarily require using XML format. Example of creation using an associative array:
$options = array();
$options['model'] = array(
'table' => array(
'name' => 'settings',
'primaryKey' => 'id'
),
'fields' => array(
array(
'type' => 'image',
'name' => 'value',
'caption' => 'Value',
'fileName' => '__ID__.__EXT__',
'thumb' => '120x80',
'isnull' => 'true',
//'uploadDirPath' => ,
//'httpPath' =>
),
array(
'type' => 'datetime',
'name' => 'cdate',
'caption' => __('Date'),
'format' => Utils::getShortDateFormat(),
'html5' => true,
'onlyList' => true,
'width' => '15%'
)
),
'actions' => array(
Store::ACTION_LIST => array(
'type' => Store::ACTION_LIST,
'caption' => __('List')
),
Store::ACTION_EDIT => array(
'type' => Store::ACTION_EDIT,
'caption' => __('Edit')
)
)
);
$store = Core::getInstance()->createStoreInstance('settings', $options);
To pass section attributes, use the @attributes
key, for example:
'actions' => array(
'@attributes' => array(
'mode' => 'buttons'
),
Store::ACTION_EDIT => array(
'type' => Store::ACTION_EDIT,
'caption' => 'Edit'
)
)
filter
Controls the placement of search fields in the DGS list:
filter="top"
Adds a button at the top to open the advanced search window
Values:
top
- Advanced search form will open in a modal windowright
- Advanced search form will slide out from the rightdefault
ornot specified
- Advanced search button won't be displayed, but quick search will be shown at the top of the tableajax
- Same asdefault
but search results will load without page reload
auditMode
Controls saving data change history in DGS.
auditMode="true"
When enabled, a __{tableName} table will be created for audit records.
CREATE TABLE `tableName` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_user` int(11) unsigned DEFAULT NULL,
`caption` varchar(100) DEFAULT NULL,
`description` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `__tableName` (
# Audit columns
`__id` int(11) unsigned NOT NULL,
`__action` varchar(100) DEFAULT NULL,
`__id_author` int(11) unsigned DEFAULT NULL,
`__action_date` datetime,
# All original columns
`id` int(11) unsigned NOT NULL,
`id_user` int(11) unsigned DEFAULT NULL,
`caption` varchar(100) DEFAULT NULL,
`description` longtext,
PRIMARY KEY (`__id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
refreshDataTimeout
There are situations when workers process data in the background, and to see changes, we have to reload the page.
For automatic data updates, refreshDataTimeout
is responsible
refreshDataTimeout="30"
Specifies the time in seconds to update data in the DGS list.
fixedHeader
Fixing column names.
fixedHeader="true"