Which columns are searched in Sonata-admin global serach

The global search parameter in Sonata Admin scans all (doctrine2) entities that have Admin classes associated with them.

I am trying to figure out how to set up a column search in a global search. On my client site, he seems to be looking for all the VARCHAR fields (doctrine type: string), and not the TEXT fields (doctrine type: text).

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

+5
source share
1 answer

According to the documentation of the sonata administrator, they mentioned that the global search module will search for all visible admins, i.e. show_in_dashboard set to true, and it will only search for fields that are configured only for the admin function configureDatagridFilters() , so the fields added to the $datagridMapper object of the admin class will be found in the global admin search in Sonata.

For example, you have a news administrator, and in configureListFields() you have 3 fields

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

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

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

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


According to the docs

"Global search" allows the end user to iterate over all visible administrators in the control panel and search by keyword. Electric current implementation is very simple, each filter associated with the string will be the default search.

ADMIN BUNDLE ~ GLOBAL SEARCH


Other Sonata Global Search Information

The search is repeated by admin class and searches for a filter using the global_search option set to true. If you use SonataDoctrineORMBundle, any text filter will be set to true by default.

By default, sonata searches for a description of the field, if it is set to a string that it automatically includes in the global search, you can also force the field to be used in the search by setting the field option to $datagridMapper add() , as shown below

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

Sonata Search

+4
source

Source: https://habr.com/ru/post/1202862/


All Articles