-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DataGridPro] Set multiple saved filters #3662
Comments
You can use |
@flaviendelangle Is it just to throw all this object from the photo below inside the method "setFilterModel"? |
Yes |
@flaviendelangle It's because this error is appearing, and I'm throwing the object inside. |
Please provide a reproduction case, working with screenshots is not great. If you want to initialize the filter when mounting the grid, use the And, if, as I understand on your screenshot, you have an internal state with the model, use the The filtering doc has a new version released this week. |
@flaviendelangle Thank you for spending time to improve the docs |
@flaviendelangle Sorry I didn't send all the code. I managed to run the method, thanks. Is it possible to execute a function after the DataGridPro is rendered? Because I need to call this function after rendering, so I can use "apiRef" and its "setFilterModel" method. I used the DataGridPro's "onStateChange" property, and it worked, whenever it updates the state, it lists the filters with the data I set by "setFilterModel". But with that, in every change of state, it calls this method that I implemented and the navigation is not cool. Do you have any properties for an initial callback of the DataGridPro rendering? |
I feel like you are doing something wrong. |
@flaviendelangle I can't access the doc you linked above. What is happening is that the "Table" button is where the DataGridPro is, and when I click on it, I call the "selectedFilters" function where it searches for the selected filters. However, when clicking on this button, what seems to me is that it is calling the function before the table exists (entering the table page), so there is no apiRef so far. I needed to put a setTimeout to wait for the time to find the apiRef and be able to execute its methods. The DataGridPro is inside the graphics state. |
Weird, it works on my computer... perhaps a problem with the preview on your browser language. If you want to share your filters between your chart and your table tab, you should probably control the filters <DataGrid
filterModel={this.state.filters}
onFilterModelChange={newModel => this.setState(prevState => ({ ...prevState, filters: newModel })
/> And if the format of the filters is not the same for the table and the charts, you can add a conversion step (which would be a lot easier with hooks, I must admit that I'm not used to work with classes anymore). <DataGridWithChartFilterModel
filterModel={this.state.filters}
onFilterModelChange={newModel => this.setState(prevState => ({ ...prevState, filters: newModel })
/>
// And then `DataGridWithChartFilterModel` is just a wrapper to convert the filterModel
class DataGridWithChartFilterModel {
static getDerivedStateFromProps(nextProps, prevState) {
if (prevState.rawFilters !== nextProps.filterModel) {
return {
rawFilters: nextProps.filterModel,
filterModel: convertFilterModelFromChartFormatToGridFormat(nextProps.filterModel),
}
}
handleFilterModelChange = (newModel) => {
const rawFilters = convertFilterModelFromGridFormatToChartFormat(newModel);
this.props.onFilterModelChange(rawFilters);
}
render() {
return (
<DataGrid
{...this.props}
onFilterModelChange={this.handleFilterModelChange}
filterModel={this.state.filterModel}
/>
)
}
} But you should avoid using imperative apis unless you absolutely need to. |
But we are entering React related topics, not DataGrid related topics here |
@flaviendelangle But using the filterModel, I can't delete 1 item from the filter. See the code and the result. |
-const filterModel = this.apiRef.current.state.filters.filterModel;
+const filterModel = gridFilterModelSelector(this.apiRef.current.state)
Either call Are you familiar with what a control mode is ? By the way, I will stop helping you based on screenshot, the discussion can continue for days like this. |
Order ID 💳
35305
Duplicates
Latest version
Summary 💡
I want to save the filter history for when I leave the page and come back, set the filters previously configured.
The problem in depth 🔍
Code used to loop through an object's keys and apply the "upsertFilterItem" method to insert an item into the filter:
Object added to filter:
In this example, the object being applied inside the "upsertFilterItem" method, is not adding the apiRef filter list.
Context 🔦
Is it possible to do it this way? Cycle through an object by entering previously saved filters before exiting the page.
This would be very useful to not have to configure filters all the time and be able to apply them to other pages.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: