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] support arbitrary filter expressions over entire record #8203

Open
2 tasks done
githorse opened this issue Mar 10, 2023 · 2 comments
Open
2 tasks done

[data grid] support arbitrary filter expressions over entire record #8203

githorse opened this issue Mar 10, 2023 · 2 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! plan: Pro Impact at least one Pro user waiting for 👍 Waiting for upvotes

Comments

@githorse
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

GridFilterItem looks like this:

export interface GridFilterItem {
  id?:      number | string;
  field:    string;
  value?:   any;
  operator: string;
}

But what if I want to filter records based on a property that's some complicated function of several fields on a record?

interface Cat {
  name:      string;
  color:     string;
  fuzziness: number;
}

function evilness({name, color, fuzziness}: Cat) {
  return color === 'black' ? Math.min(1.0, 1.2 * adorableness(name)) : fuzziness * 0.8 
}

cats.filter(cat => evilness(cat) > 0.5)

Ok, I can do that by defining a calculated hidden evilness column in advance:

const columns = [
  ...,
  { 
    field: 'evilness',
    valueGetter: ({row}) => evilness(row),
  }
]

But this is a workaround, and requires me to mess with columnVisibilityModel, etc. It also requires me to know all these calculated properties in advance.

It would be cool if I could skip the middleman here and just define something like valueGetter directly in the GridFilterItem:

export interface GridFilterItem<Record, Value> {
    id?:      number | string;
    field:    string | (record: Record) => Value;
    value?:   Value;
    operator: string;
}

Examples 🌈

No response

Motivation 🔦

I have an existing filtering ecosystem, outside of the grid, where I can define arbitrary filtering functions like this. If the DataGrid could handle filters like this it would be a cinch to interface my filtering widgets directly with the DataGrid filtering apparatus. As it stands, it's possible (using the pseudocolumn) but clunky.

Order ID 💳 (optional)

46840

@githorse githorse added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 10, 2023
@zannager zannager added component: data grid This is the name of the generic UI component, not the React module! plan: Pro Impact at least one Pro user labels Mar 13, 2023
@m4theushw m4theushw added waiting for 👍 Waiting for upvotes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 13, 2023
@m4theushw
Copy link
Member

If I understood correctly you want to add a column only visible inside the filter panel and with a custom operator. Currently we don't support this use case but I added the "waiting for upvotes 👍" label to see if other users also would like to have this supported.

@m4theushw m4theushw changed the title support arbitrary filter expressions over entire record [data grid] support arbitrary filter expressions over entire record Mar 13, 2023
@githorse
Copy link
Author

Makes sense @m4theushw -- but to clarify I think I don't (necessarily) need a custom operator here, but instead a custom field in the style of a valueGetter expression. In the example above, the operator would just be the standard >:

const filterItem = {
  id:       0,
  field:    ({record: cat}) => evilness(cat),  <-- new feature here
  operator: '>',
  value:    0.5
}

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! plan: Pro Impact at least one Pro user waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

3 participants