Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Quick Filter / Search grid data #3701

Open
Ben-CA opened this issue Feb 7, 2025 · 1 comment
Open

Quick Filter / Search grid data #3701

Ben-CA opened this issue Feb 7, 2025 · 1 comment

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}
/>

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

No branches or pull requests

1 participant