Wednesday, November 25, 2015

Magento2: Search By Keyword is not working in admin grid of custom module

If your custom module is working fine with filter and other functions And you are facing issue with Search By Keyword functionality then this tips or answer will helpful to you.

Generally, this become happened due to missing of index creation for your module grid table.

You have to create a table index for faster searching mechanism for your grid table.

1. Open and edit your module's InstallSchema.php from <Vendor> /<ModuleName>/Setup/InstallSchema.php

At the end of table creation script/ table modify script add following code to create a table index.

Note: this example is for Fulltext index type.

1:  ->addIndex(  
2:                      $setup->getIdxName(  
3:                           $setup->getTable('table_name'),  
4:                           ['field1', 'field2', 'field2'],  
5:                           \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT  
6:                      ),  
7:                      ['field1', 'field2', 'field3'],  
8:                      ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT]  
9:                 )  
Note: You can apply this code to UpgradeSchema.php if you had created module finally.
2. You must check the filterSearch section is added into view/adminhtml/ui_component/xyz_listing.xml.  
Please update the relevant value with item 'provider', 'chipsProvider' & 'storageConfig'
 
Flush the cache and test your code.

12 comments:

  1. Do you know where I can find described in detail these XML sections together with their elements/attributes. I don't understand chipsProvider, storageConfig, and a lot more...
    Can you help? thanks

    ReplyDelete
  2. Hi, you may refer complete guideline here http://devdocs.magento.com/guides/v2.0/ui-components/ui-component.html

    ReplyDelete
  3. Thanks for sharing, but now the version is 2.2.5 so it kinda old now, can you update?

    ReplyDelete
  4. https://www.maximehuran.fr/en/filters-creation-on-adminhtml-grid-with-magento-2/
    full part of this is here

    ReplyDelete
  5. Can you please say How can we achieve keyword search with products grid???

    ReplyDelete
  6. Thank you for your help, very good article!

    ReplyDelete
  7. Thank you for sharing such useful information. I really enjoyed while reading your article and it is good to know the latest updates. Do post more. And also read about Magento 2 Development Company

    ReplyDelete