[英]Predefined parameters for Sonata list search
I need to set several predefined options for showing list of entities. 我需要设置几个预定义的选项来显示实体列表。
Sonata code: 奏鸣曲代码:
class SubscriptionAdmin extends Admin {
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('created_at')
->add('status', 'doctrine_orm_choice', [], 'choice', ['choices' = ['active'=>'ecmo.enum.user.active', 'inactive'=>'ecmo.enum.user.active']
;
}
How i can set, that, by default, sonata show only active users, sorted by created_at
? 我如何设置,默认情况下,奏鸣曲仅显示活动用户(按created_at
排序)?
You could do this, setting the default values for the $datagridValues variable as below 您可以这样做,为$ datagridValues变量设置默认值,如下所示
class SubscriptionAdmin extends Admin
{
/**
* Default Datagrid values
*
* @var array
*/
protected $datagridValues = array (
'status' => array ('type' => 1, 'value' => 1), // field status with value 1
'_page' => 1, // Display the first page (default = 1)
'_sort_order' => 'ASC', // Descendant ordering (default = 'ASC')
'_sort_by' => 'name' // name of the ordered field (default = the model id field, if any)
// the '_sort_by' key can be of the form 'mySubModel.mySubSubModel.myField'.
);
}
Where 'status' should be substituted by the field that you want and you should specify the desired value, and 'type' value corresponds with the following: 其中“状态”应替换为所需的字段,并应指定所需的值,“类型”值对应以下内容:
1: =
2: >=
3: >
4: <=
5: <
That's to filter an integer field. 那是为了过滤一个整数字段。 In my case, I've used this without specifying type, and the value 1 is set as default. 就我而言,我在未指定类型的情况下使用了它,并且将值1设置为默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.