列表列是供列表使用的列定义。以下区域引用了这些。
所有列表列都被识别为它们各自的类型属性。
columns:
mycolumn:
type: number
# ...以下列表列可用:
文本
数字
图片
开关
摘要
日期和时间
可选
联动
部分
颜色选择器
货币
对于每一列可以指定这些属性(如适用):
| Property | Description |
|---|---|
| label | a name when displaying the list column to the user. |
| type | defines how this column should be rendered. |
| default | specifies the default value for the column if value is empty. |
| searchable | include this column in the list search results. Default: false. |
| invisible | specifies if this column is hidden by default. Default: false. |
| sortable | specifies if this column can be sorted. Default: true. |
| sortableDefault | specifies if this column is sorted by default. This should only be used on a single sortable column. Supported values: asc, desc. |
| clickable | if set to false, disables the default click behavior when the column is clicked. Default: true. |
| select | defines a custom SQL select statement to use for the value. If a relation is specified, this refers to a column on the related database table. |
| valueFrom | defines a model attribute to use for the source value. If a relation is specified, this refers to the attribute of the relation and eager loads the relation. |
| displayFrom | defines a model attribute to use for the display value. |
| relation | defines a model relationship name as a source, used with select or valueFrom. |
| relationCount | display the number of related records as the column value. Must be used with the relation option. Default: false |
| relationWith | eager load the specified relation definition with the list query. Useful to improve performance of nested column selections. |
| cssClass | assigns a CSS class to the column container. |
| headCssClass | assigns a CSS class to the column header container. |
| width | sets the column width, can be specified in percents (10%) or pixels (50px). There could be a single column without width specified, it will be stretched to take the available space. |
| align | specifies the column alignment. Possible values are left, right and center. |
| permissions | the permissions that the current backend user must have in order for the column to be used. Supports either a string for a single permission or an array of permissions of which only one is needed to grant access. |
| order | a numerical weight when determining the display order, default value increments at 100 points per column. |
| after | place this column after another existing column name using the display order (+1). |
| before | place this column before another existing column name using the display order (-1). |
| tooltip | adds an icon with a tooltip after the column label. See below for more detailed settings. |
可以更改每列的源值和显示值。如果你想从另一列获取列值,请使用 valueFrom 选项。
other_name:
label: Something Great
valueFrom: name如果你想保留源列的值,但显示模型属性中的另一个值,请使用 displayFrom 选项。
status_code:
label: Status
displayFrom: status_label这主要适用于当 模型访问器 用于修改显示值时。这在您想要显示某个值,但按不同的值进行排序和搜索时很有用。
public function getStatusLabelAttribute()
{
return title_case($this->status_code);
}在某些情况下,从嵌套数据结构中检索列值是有意义的,例如 模型关系 列或 可 JSON 化数组。以下示例将查找 PHP 中等同于 $record->content->title 或 $record->content['title'] 的对应值。
content[title]:
name: Title
sortable: false这样做唯一的缺点是该列无法使用可搜索或可排序选项。为了使该列可搜索,并出于性能考虑,我们建议使用模型事件在本地数据库表中复制其值。或者,您可以使用下文进一步描述的 relation 属性。
select 属性允许您使用自定义的 SELECT 语句创建一个列。任何有效的 SQL SELECT 语句均可在此处使用。
full_name:
label: Full Name
select: concat(first_name, ' ', last_name)该 relation 属性允许您将相关列作为数据库查询的一部分显示,从而允许对该列进行搜索和排序。该 relation 被设置为 模型关系 的名称。在下一个示例中 该 名称 值将被翻译成 name 属性在相关模型中找到的(例如:$model->name)。
group_name:
label: Group
relation: groups
select: name要显示一个显示相关记录数量的列,请使用 relationCount 属性。
users_count:
label: Users
type: number
relation: users
relationCount: trueBe careful not to name relations the same as existing database columns. For example, using a name
group_idcould break the group relation due to a naming conflict.
tooltip 属性通过在列标题中添加一个信息图标来增强列表列。悬停在此图标上会显示一个工具提示,提供关于该列的额外上下文或详细信息。此功能有助于为用户提供指导或澄清,以便理解列内容。
count:
label: Count
type: number
tooltip: Number of users in the group除了提供工具提示 title,你还可以指定 icon (可用图标) 以及 placement (right, bottom, left, 默认值为 top) 的工具提示。
count:
label: Count
type: number
tooltip:
title: Number of users in the group
placement: bottom
icon: icon-users