typeorm-mui-query
v1.3.1
Published
MUI TypeORM QueryBuilder
Downloads
146
Readme
MUI TypeORM QueryBuilder
If you use TypeORM and MUI Data Grid server-side filter or server-side sorting this project can be helpful.
Install
npm install typeorm-mui-query
Example
Frontend
const [queryOptions, setQueryOptions] = useState({
filterModel: {
items: [],
},
sortModel: [],
})
const handleSortModelChange: DataGridProProps['onSortModelChange'] = useCallback((sortModel) => {
setQueryOptions((currentState) => ({ ...currentState, sortModel }))
}, [])
const handleFilterModelChange: DataGridProProps['onFilterModelChange'] = useCallback(
(filterModel) => {
setQueryOptions((currentState) => ({ ...currentState, filterModel }))
},
[]
)
const query = new URLSearchParams({
...queryOptions,
sortModel: JSON.stringify(queryOptions.sortModel),
filterModel: JSON.stringify(queryOptions.filterModel),
})
const results = await API.get('default', `/example?${query.toString()}`, {})
Backend
import { handleQuery } from 'typeorm-mui-query'
handleQuery({ qb, queryStringParameters })
const results = await qb.getMany()