doushi8231 2014-09-18 09:34
浏览 59
已采纳

在Sonata-Admin全局搜索中搜索哪些列

The global search option in Sonata Admin searches trough all the (doctrine2) entities that have Admin Classes associated with them.

What I am trying to figure out is how to configure what columns get searched by the global search. In my clients website it seems to be searching trough all VARCHAR fields (doctrine type: string) and not the TEXT fields (doctrine type: text).

Does anybody know why this is, and how it can be changed?

  • 写回答

1条回答 默认 最新

  • duanchu2607 2014-09-18 11:55
    关注

    According to sonata admin's documentation they have mentioned that global search module will search for all visible admins i.e show_in_dashboard is set to true, and it will search in only those fields which are in configured admin's configureDatagridFilters() function only,So the fields added to $datagridMapper object of admin class will be searched in Sonata admin's global search.

    For example you have news admin and in configureListFields() you have 3 fields

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('name')
            ->add('createdDate');
    }
    

    And in configureDatagridFilters() you have only name field to filter results

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper->add('name');
    }
    

    So Sonata will search in only name field of your news admin because you have configured a filter for this admin,So this filter is also used in global search for admin and no other field will be searched except name field


    According to docs

    The "global search" allows the end user to iterate over all visible admins in the dashboard and search for the keyword. The current implementation is very simple, every filter related to a string will be searchable by default.

    ADMIN BUNDLE ~ GLOBAL SEARCH


    Other information regarding sonata global search is

    The search iterates over admin classes and look for filter with the option global_search set to true. If you are using the SonataDoctrineORMBundle any text filter will be set to true by default.

    By default sonata looks for field description if set to string it automatically involves in global search you can also force field to be used in search by setting field option in $datagridMapper's add()like below

    ->add('name', null, array('global_search' => true), null, array()
    

    Sonata Search

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

报告相同问题?

悬赏问题

  • ¥15 速帮,学校需要在外上班没空
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义