3

How to make my search bar work in my custom grid module? I have added the search field by inserting this code <filterSearch name="fulltext"/> inside my <listingToolbar name="listing_top"> tag.

The search field have been displayed but it's not working, what should I do?

3 Answers 3

5

Using the new declarative schema (2.3+):

  1. on a db_schema.xml add:
<table name="something_grid">
    <index referenceId="SOME_INDENTIFIER" indexType="fulltext">
        <column name="custom_column_1"/>
        <column name="custom_column_2"/>
        <column name="custom_column_n"/>
    </index>
</table>

Important: if you are extending a preexisting grid with new columns, you will need to find it's <module>_grid.xml declaration and make sure to use the same referenceId for that table on your db_schema.xml

  1. run a bin/magento setup:upgrade
  2. have fun and buy me a coffee :D

Reference: https://devdocs.magento.com/guides/v2.4/extension-dev-guide/declarative-schema/db-schema.html#add-an-index

2

fulltext search only work if you have add index in your database table. to add Index in your table use below code.

$setup->getConnection()->addIndex(
    $setup->getTable('quote_id_mask'),
    $setup->getIdxName('quote_id_mask', ['masked_id']),
    ['masked_id']
);

Reference

1
1

**

A full-text search, also known as a keyword search, is a functionality that can produce more relevant results by scanning a considerable number of fields in the Magento 2 admin grid. Therefore, adding the full-text search in Magento 2 grid can help the admin search more efficiently and faster.

However, the Magento 2 keyword search functionality sometimes fails to work and might not provide accurate results. Thus, you can follow the below steps to fix the Magento 2 keyword search now working in the custom Module Admin Grid View,

To add the Full-text or Keyword search functionality in Magento 2 custom module admin grid view, you must create and add an index of the table. You can do it by calling the addIndex() function in the below file.,

\app\code\Vendor\Extension\Setup\InstallSchema.php

Below provided is the code to make an index of the table and add the keyword search functionality in Magento 2 Admin grid view:

$connection->addIndex(
                    'testtable', //table name'title',    // index name
                    [
                        'title'   // filed or column name 
                    ],           \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT //type of index
                );

You must add the table name and column names in the above code to add the keyword search in Magento 2 admin grid view.

I hope the above solution helps you to resolve the "Custom Module Admin Grid View "Search by Keyword" Not Working" issue. However, if the issue persists, you can update it here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.