dropdown - 从多个项目中单选进行筛选。
status:
type: dropdown
options:
pending: Pending
active: Active
closed: Closed以下属性可用于此过滤器。
| Property | Description |
|---|---|
| options | available options for the filter, as an array. |
| optionsMethod | take options from a method defined on the model or as a static method, eg Class::method. |
| conditions | a custom SQL select statement to use for the filter. |
| emptyOption | text to display when there is no available selections. |
| modelScope | applies a model query scope method to the filter query, can be a model method name or a static PHP class method (Class::method). The first argument will contain the model query that the widget will be attaching its value to, i.e. the parent model. |
你可以将自定义 SQL 作为字符串传递给条件,其中 :value 包含过滤后的值.
status:
type: dropdown
conditions: status = :value
# ...下拉筛选器不显示标签,emptyOption 属性可用于设置默认状态。
status:
type: dropdown
emptyOption: Select Status
# ...您可以使用以下示例在模型中定义一个自定义的 modelScope。
status:
label: Status
type: dropdown
modelScope: applyStatusCode
options:
active: Active
deleted: Deleted在 $scope->value 中找到值的 scopeApplyStatusCode 方法定义。
public function scopeApplyStatusCode($query, $scope)
{
if ($scope->value === 'active') {
return $query->withoutTrashed();
}
if ($scope->value === 'deleted') {
return $query->onlyTrashed();
}
}您可以通过将一个模型方法传递给 optionsMethod 属性来动态地提供选项
status:
label: Status
type: dropdown
optionsMethod: getStatusOptionsgetStatusOptions 方法定义。
public function getStatusOptions()
{
return [
'active' => 'Active',
'deleted' => 'Deleted',
];
}