Skip to content

Quick Filter / Search grid data #3701

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Ben-CA opened this issue Feb 7, 2025 · 2 comments
Closed

Quick Filter / Search grid data #3701

Ben-CA opened this issue Feb 7, 2025 · 2 comments

Comments

@Ben-CA
Copy link

Ben-CA commented Feb 7, 2025

Use case

Would be nice if there was integrated full search / filtering support, rather than having to develop such separately.

Proposed solution

Something like this:
https://www.ag-grid.com/react-data-grid/filter-quick/

AG Grid supports a zillion things, many of which are not needed in a small project. But almost every data grid "should" have a search field. (And because of virtualization, the Ctrl + F in-browser search won't work.)

@Ben-CA
Copy link
Author

Ben-CA commented Feb 7, 2025

I suppose this can be added fairly easily separate from the grid itself:

  const filteredRows = useMemo(() => {
    if (filterText === "") { return rows; } // bypass filtering if no search term
    const lowerCaseFilter = filterText.toLowerCase();
    return rows.filter(row => {
      return Object.keys(row).some(key => {
        return String(row[key]).toLowerCase().includes(lowerCaseFilter);
      });
    });
  }, [rows, filterText]);

Where you have an input set the filterText, rows is the original data, and then you reference the filtered rows like this:

<DataGrid
        columns={columns}
        rows={filteredRows}
/>

@amanmahajan7
Copy link
Contributor

We do not have any plans to add search/filter functionality as it can be quite specific and easily implemented outside the grid. We will be happy to accept a PR with an example

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants