MUI Data Grid FilterModel: Set, Control, and Debug Filters
A MUI Data Grid filterModel is an object with an items rule list and a logicOperator; each current rule normally uses field, operator, and value. Use it when filters must be set from code, saved in URL or application state, translated for an API, or kept in sync with another part of your UI.
MUI enables column filtering by default. Users can open it from a column menu by choosing Filter, or from the toolbar’s Filters control when that control is enabled.
What the MUI Data Grid FilterModel Does
Each object in filterModel.items represents one filtering rule. A rule answers four questions:
- Which column should the rule evaluate? Use
field. - Which comparison should it use? Use
operator. - What should it compare against? Use
value. - How should the grid identify this rule? Use
idwhen the model has multiple rules.
Here is the shape of a current MUI X filter model:
const filterModel = {
items: [
{
id: 'rating-minimum',
field: 'rating',
operator: '>',
value: '2.5',
},
],
logicOperator: GridLogicOperator.And,
};
The operator is not the label displayed in the filter panel. It must match the operator object’s value key. For example, a text operator can use contains, while a numeric operator can use >.
The logicOperator determines how multiple rules work together:
ANDmeans every rule must match for a row to remain visible.ORmeans at least one rule must match.
A single-item model does not need a combination decision, but setting logicOperator explicitly makes the model easier to extend later.
How To Set a MUI Data Grid FilterModel
Choose the way the grid should receive its model before wiring up the component.
| Goal | Best approach | What happens after the grid renders |
|---|---|---|
| Keep filters in React state, a URL, or an API request | Controlled filterModel |
Your application owns every filter update |
| Apply a default filter once | initialState.filter.filterModel |
The initial model is used only on first render |
| Change filters from a button, dialog, or custom UI | apiRef.current.setFilterModel() |
The grid updates immediately |
Step 1: Define a Controlled Filter Model
A controlled filter is the most reliable default when filters affect application state or server requests. Import the model type and logic enum from the same MUI X package as your grid.
import * as React from 'react';
import {
DataGrid,
GridFilterModel,
GridLogicOperator,
} from '@mui/x-data-grid';
const initialFilterModel: GridFilterModel = {
items: [
{
id: 'status-active',
field: 'status',
operator: 'equals',
value: 'active',
},
],
logicOperator: GridLogicOperator.And,
};
Create React state from that model:
const [filterModel, setFilterModel] =
React.useState<GridFilterModel>(initialFilterModel);
Use the actual column field value, not its header label. If a column is declared as { field: 'status', headerName: 'Account Status' }, the filter item must use field: 'status'.
Step 2: Pass the Model and Change Handler to DataGrid
Pass both filterModel and onFilterModelChange. A controlled grid must receive the newly updated model after the user changes a filter; otherwise, the UI can appear to accept a change and then revert.
<DataGrid
rows={rows}
columns={columns}
filterModel={filterModel}
onFilterModelChange={setFilterModel}
/>
The callback receives the complete next model. Store that model rather than trying to manually patch one property in existing state.
The current MUI X filtering documentation uses filterModel for controlled filtering and onFilterModelChange to receive grid-driven changes.
Step 3: Add Multiple Rules With Stable IDs
Give every item an id when more than one filter is present. IDs let MUI update, remove, and reorder individual rules safely.
setFilterModel({
items: [
{
id: 'status-active',
field: 'status',
operator: 'equals',
value: 'active',
},
{
id: 'rating-minimum',
field: 'rating',
operator: '>',
value: '2.5',
},
],
logicOperator: GridLogicOperator.And,
});
In a grid edition that supports multiple filter items, this model requires rows to have status active and a rating greater than 2.5.
To show rows matching either condition, change the combination:
logicOperator: GridLogicOperator.Or
Use GridLogicOperator.And or GridLogicOperator.Or rather than guessing at serialized string values. If users must edit more than one rule through the standard filter UI, confirm that your installed Data Grid edition and version supports multi-filtering.
Step 4: Test the Filter in the Grid UI
Open a column menu and select Filter, then create a rule matching the model you configured. If the toolbar filter control is enabled, use Filters to inspect the same filtering state.
Confirm three things:
- The expected rows remain visible.
- The filter panel shows the intended field, operator, and value.
- React state changes when a user edits or removes a rule.
If the filter panel displays an unexpected operator or no matching rows, check the column type and the value used for filtering before changing the model structure.
Initialize or Change Filters Programmatically
Use initialState when the grid needs a default filter but your component does not need to control later user edits.
<DataGrid
rows={rows}
columns={columns}
initialState={{
filter: {
filterModel: {
items: [
{
id: 'priority-high',
field: 'priority',
operator: 'equals',
value: 'high',
},
],
logicOperator: GridLogicOperator.And,
},
},
}}
/>
initialState is initialization only. Updating the object later does not update an already mounted grid. Use the controlled filterModel prop when a filter must react to a button, route change, saved search, or external state update.
For imperative controls, use apiRef and set the complete model:
import { useGridApiRef } from '@mui/x-data-grid';
const apiRef = useGridApiRef();
<DataGrid
apiRef={apiRef}
rows={rows}
columns={columns}
/>
apiRef.current.setFilterModel({
items: [
{
id: 'name-search',
field: 'name',
operator: 'contains',
value: 'sam',
},
],
logicOperator: GridLogicOperator.And,
});
You can also open the filter panel for a target column:
apiRef.current.showFilterPanel('name');
Passing a column field to showFilterPanel() opens filtering for that field and adds a rule for it.
A column marked filterable: false cannot be changed by users in the filter UI, but code can still apply a filter to it through filterModel or setFilterModel(). That filter is read-only in the UI. Do not treat a client-side filter as an authorization boundary: rows sent to the browser are still available to the browser.
Make Sure the Grid Filters the Right Value
The value users see is not always the value MUI filters.
A filter evaluates the value from the column’s field or from its valueGetter. A valueFormatter only changes rendering; it does not change the candidate value that filter operators receive.
For example, a price column may render $1,250.00 with a valueFormatter, while its underlying value is 1250. A numeric filter should use the numeric field or a numeric valueGetter, not the formatted currency text.
Similarly, if your rows store firstName and lastName but users need to search a full name, create a column value that resolves to the full name through valueGetter. Do not expect a display-only formatter to make "Ada Lovelace" searchable.
The legacy MUI v4 filtering API documents this distinction explicitly: field and valueGetter supply the filter candidate, while valueFormatter is for rendering.
For custom comparisons, define a custom GridFilterOperator and add it to the column’s filterOperators array. Its value becomes the operator stored in the model. Keep that value stable if you save filters in a URL, local storage, or database.
Use FilterModel With Server-Side Filtering
For server-side filtering, keep the same controlled model but set the grid to server mode and send the next model to your backend.
<DataGrid
rows={rows}
columns={columns}
filterMode="server"
filterModel={filterModel}
onFilterModelChange={handleFilterModelChange}
/>
Handle the next model directly:
const handleFilterModelChange = (nextModel: GridFilterModel) => {
setFilterModel(nextModel);
void loadOrders(nextModel);
};
Build API parameters from nextModel.items and nextModel.logicOperator. Avoid reading filterModel immediately after calling setFilterModel, because React state updates are asynchronous and may still hold the previous model.
Your API does not need to use MUI operator names. Translate them at the boundary instead:
const operatorMap: Record<string, string> = {
contains: 'contains',
equals: 'eq',
'>': 'gt',
'<': 'lt',
};
function toApiFilters(model: GridFilterModel) {
return {
logic: model.logicOperator,
filters: model.items.map((item) => ({
field: item.field,
operator: operatorMap[item.operator] ?? item.operator,
value: item.value,
})),
};
}
This keeps the grid’s client-side operator definitions independent from an API dialect such as OData, SQL-inspired query syntax, or an internal search service.
Avoid Version-Specific FilterModel Mistakes
Filter-model keys are version-sensitive, so a model copied from older MUI documentation may not work in a current MUI X grid.
Current models use these properties:
{
field: 'status',
operator: 'equals',
value: 'active',
}
Older MUI Data Grid versions used names such as:
{
columnField: 'status',
operatorValue: 'equals',
value: 'active',
}
Do not mix the two shapes. In current MUI X, use field and operator; when maintaining an older application, confirm the exact property names in the filtering API documentation for the MUI X version installed in that project.
This matters especially when:
- Migrating from MUI v4 or early MUI X releases.
- Restoring saved filters created by an older application version.
- Sharing models between applications that use different MUI X versions.
- Copying code from old issue discussions or tutorials.
If stored filters can outlive an application upgrade, add a small migration function that converts old keys before passing data to the grid.
Troubleshoot Common FilterModel Problems
| Symptom | Likely cause | Fix |
|---|---|---|
| A user changes a filter but it immediately resets | The grid is controlled, but onFilterModelChange does not update state |
Store the complete next model in state |
| A multi-filter model throws an ID-related error | One or more items entries has no id |
Add a unique stable id to every item |
| Filtered results are empty unexpectedly | Rules use AND, but the intended behavior is “either condition” |
Change to GridLogicOperator.Or |
| A formatted value does not match a filter | The display text comes from valueFormatter |
Filter the field value or create a suitable valueGetter |
| A filter works in an old project but not a new one | The model uses columnField or operatorValue |
Convert to current field and operator keys |
| The backend rejects an operator | The API expects different operator names | Translate MUI operators before sending the request |
| A filter cannot be edited in the panel | The column is marked filterable: false |
Keep it read-only or make the column filterable if users should edit it |
Confirm Filters Before Shipping
Use this short checklist before relying on a filter model in production:
- Every filter item points to an existing column
field. - The
operatoris valid for that column’s data type. - Every item has an
idwhen multiple filters are active. - The
logicOperatormatches the intendedANDorORbehavior. - A filtered column with derived data uses
valueGetterwhen needed. - Controlled grids write the complete next model from
onFilterModelChange. - Server-side grids serialize the callback’s
nextModel, not stale React state. - Automated tests assert the visible row IDs for one-rule and multi-rule cases.
Test at least one case where no rows match, one where exactly one row matches, and one where multiple rules differ between AND and OR. Those cases catch most incorrect fields, operators, and combination logic.
Frequently Asked Questions
Do I need an id for every filter item?
You must give each item an id when filterModel.items contains multiple rules. A single filter item may work without one, but using stable IDs from the start makes saved filters, rule removal, and later multi-filter support more reliable.
Why does my formatted cell text not filter correctly?
Filtering uses the column field value or its valueGetter, not the text returned by valueFormatter. Put search-ready or comparison-ready data in the row field or valueGetter, and reserve valueFormatter for presentation such as currency, dates, and display labels.
Can I filter a column with filterable: false?
Yes. You can set a filter for a non-filterable column through filterModel or apiRef.current.setFilterModel(). The rule applies, but users cannot edit it through the standard filtering UI.
Should I use operator or operatorValue?
Use operator in current MUI X filter models, together with field and value. Use operatorValue only when maintaining an older Data Grid version whose installed filtering API still expects the older model shape.
How do I open the filter panel from custom code?
Call apiRef.current.showFilterPanel('fieldName') after the grid has mounted. For example, showFilterPanel('name') opens filtering for the name column and adds a filter rule for that field.
