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 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数