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

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

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证