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

[data grid] Customize GridColumnsPanel search function #6453

Closed
2 tasks done
teryngull opened this issue Oct 11, 2022 · 2 comments · Fixed by #6557
Closed
2 tasks done

[data grid] Customize GridColumnsPanel search function #6453

teryngull opened this issue Oct 11, 2022 · 2 comments · Fixed by #6557
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability enhancement This is not a bug, nor a new feature plan: Pro Impact at least one Pro user

Comments

@teryngull
Copy link

teryngull commented Oct 11, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Hello, in the existing code

const currentColumns = React.useMemo(() => {

it appears to look for a headerName or the field to filter the search results for the columns in the GridColumnsPanel. It would be nice if this could also look at the description. We have a column called MPH, but we would like to be able to search for "Mile" and find this column in the list, based on the description being "Miles per hour". This is a change that would affect everyone, and not everyone may like this, so, it might be nice if there was a way to indicate what fields it should search across or to customize this search function instead.

I found this previous PR, which changed the logic to what it has today:
#3959

Examples 🌈

No response

Motivation 🔦

Our column headers typically will have an abbreviation in it, and the description column will have the fully spelled out names available when hovering over these column headers. For example, we have a column that we have titled "MPH" as the headerName, and the description is "Miles per hour". When searching for a field in the columns panel, we'd like to show this column when searching for "mile" and not just "MPH".

Searching for "mph" returns the column:
image

Searching for "mile", however, does not return this column.

Order ID 💳 (optional)

42641

@teryngull teryngull added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 11, 2022
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Oct 14, 2022
@flaviendelangle flaviendelangle changed the title [Data Grid] Customize GridColumnsPanel search function [data grid] Customize GridColumnsPanel search function Oct 17, 2022
@cherniavskii cherniavskii added the plan: Pro Impact at least one Pro user label Oct 17, 2022
@cherniavskii
Copy link
Member

Hey @teryngull
Thanks for opening this issue!

We can add a prop to GridColumnsPanel component that will override default filter predicate function:

const columnsSearchPredicate = (column: GridStateColDef, searchValue: string) => {
  return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1
    || (column.description || '').toLowerCase().indexOf(searchValue) > -1;
}

<DataGrid
  // ...
  componentsProps={{
    columnsPanel: {
      searchPredicate: columnsSearchPredicate,
    }
  }}
/>

Would that work for you?

@cherniavskii cherniavskii added feature: Other customization: extend Logic customizability enhancement This is not a bug, nor a new feature status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 17, 2022
@teryngull
Copy link
Author

Yes, that would work perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability enhancement This is not a bug, nor a new feature plan: Pro Impact at least one Pro user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants