[英]Predefined parameters for Sonata list search
我需要設置幾個預定義的選項來顯示實體列表。
奏鳴曲代碼:
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']
;
}
我如何設置,默認情況下,奏鳴曲僅顯示活動用戶(按created_at
排序)?
您可以這樣做,為$ 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'.
);
}
其中“狀態”應替換為所需的字段,並應指定所需的值,“類型”值對應以下內容:
1: =
2: >=
3: >
4: <=
5: <
那是為了過濾一個整數字段。 就我而言,我在未指定類型的情況下使用了它,並且將值1設置為默認值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.