mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.03k stars 1.24k forks source link

[data grid] Include columnType in GridFilterItem #11809

Open levireciprocity opened 7 months ago

levireciprocity commented 7 months ago

Summary

Add the type field to the GridFilterItem interface on the GridFilterModel, this field would help for server-side datagrid filtering https://v5.mui.com/x/react-data-grid/column-definition/#column-types

Examples

instead of specifying the column field on the backend i could grab the column type from the api to determine filter operators and logic

Motivation

make server-side datagrid filtering more generic

Search keywords: type GridFilterItem GridFilterModel server-side filtering

michelengelen commented 7 months ago

What exactly are you trying to do? Could you give an example in code?

Just asking because you can get the type from your column definition with the mandatory field property on the GridFilterItem.

It could look something like this:

const handleFilterModelChange = (model: GridFilterModel) => {
  const modelItemsWithType: Array<GridFilterItem & { type: GridColDef['type'] }> =
    model.items.map((item) => ({
      ...item,
      type: apiRef.current.getColumn(item.field).type,
    }));
  console.log('itemsWithType', modelItemsWithType);
};

Here is a working example of that handler: FilterModelItems with type

levireciprocity commented 7 months ago

Yeah this is the solution I have, rather than mapping through the items to get the type I'd like to just have the type on the GridFilterItem with operatorValue, value, columnField and id

michelengelen commented 7 months ago

OK, imo this should be sufficient and not blur the API even more, but I'll put this on the board nonetheless for the team to look at.