|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { Grid, Link, useTheme } from '@mui/material'; |
7 | | -import { DataGrid, GridColDef, GridRow, GridRowProps, GridToolbar } from '@mui/x-data-grid'; |
| 7 | +import { DataGrid, GridColDef, GridFilterModel, GridRow, GridRowProps, GridToolbar } from '@mui/x-data-grid'; |
8 | 8 | import { useState } from 'react'; |
9 | 9 | import { Link as RouterLink } from 'react-router-dom'; |
10 | 10 | import { Project, WbsElementStatus } from 'shared'; |
@@ -114,6 +114,11 @@ const ProjectsTable: React.FC = () => { |
114 | 114 | } |
115 | 115 | ]; |
116 | 116 |
|
| 117 | + const filterValues = JSON.parse( |
| 118 | + // sets filter to a default value if no filter is stored in local storage |
| 119 | + localStorage.getItem('projectsTableFilter') ?? '{"columnField": "carNumber", "operatorValue": "=", "value": ""}' |
| 120 | + ); |
| 121 | + |
117 | 122 | const theme = useTheme(); |
118 | 123 | return ( |
119 | 124 | <Grid container xs={12}> |
@@ -162,7 +167,21 @@ const ProjectsTable: React.FC = () => { |
162 | 167 | quickFilterProps: { debounceMs: 500 } |
163 | 168 | } |
164 | 169 | }} |
| 170 | + onFilterModelChange={(filterModel: GridFilterModel) => { |
| 171 | + localStorage.setItem('projectsTableFilter', JSON.stringify(filterModel.items[0])); |
| 172 | + }} |
165 | 173 | initialState={{ |
| 174 | + filter: { |
| 175 | + filterModel: { |
| 176 | + items: [ |
| 177 | + { |
| 178 | + columnField: filterValues.columnField, |
| 179 | + operatorValue: filterValues.operatorValue, |
| 180 | + value: filterValues.value |
| 181 | + } |
| 182 | + ] |
| 183 | + } |
| 184 | + }, |
166 | 185 | sorting: { |
167 | 186 | sortModel: [{ field: 'wbsNum', sort: 'asc' }] |
168 | 187 | }, |
|
0 commit comments