dousunle5801 2014-05-17 11:02
浏览 38
已采纳

Sonata列表搜索的预定义参数

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 ?

  • 写回答

1条回答 默认 最新

  • dongyun9120 2014-05-17 17:47
    关注

    You could do this, setting the default values for the $datagridValues variable as below

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大