Skip to content

Commit 97fb630

Browse files
authored
Merge pull request #1552 from Northeastern-Electric-Racing/#1167-persistent-filters-for-projects-table
#1167 persistent filters for projects table
2 parents c19058e + 3e6e835 commit 97fb630

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/frontend/src/pages/ProjectsPage/ProjectsTable.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
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';
88
import { useState } from 'react';
99
import { Link as RouterLink } from 'react-router-dom';
1010
import { Project, WbsElementStatus } from 'shared';
@@ -114,6 +114,11 @@ const ProjectsTable: React.FC = () => {
114114
}
115115
];
116116

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+
117122
const theme = useTheme();
118123
return (
119124
<Grid container xs={12}>
@@ -162,7 +167,21 @@ const ProjectsTable: React.FC = () => {
162167
quickFilterProps: { debounceMs: 500 }
163168
}
164169
}}
170+
onFilterModelChange={(filterModel: GridFilterModel) => {
171+
localStorage.setItem('projectsTableFilter', JSON.stringify(filterModel.items[0]));
172+
}}
165173
initialState={{
174+
filter: {
175+
filterModel: {
176+
items: [
177+
{
178+
columnField: filterValues.columnField,
179+
operatorValue: filterValues.operatorValue,
180+
value: filterValues.value
181+
}
182+
]
183+
}
184+
},
166185
sorting: {
167186
sortModel: [{ field: 'wbsNum', sort: 'asc' }]
168187
},

0 commit comments

Comments
 (0)