-
Hello to all, i have a simple question about how filter work.
Of course the DataGrid filter allow me to input an integer on the filter, how can i change this behaviour? I would like to show the operator name on the filter and then query the backend with the operator id. Thanks to all |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hey @dj-fiorex , |
Beta Was this translation helpful? Give feedback.
-
Oh yes, i will try to explain better
OPERATIONS
This is the list component of the resource OPERATION export const OperationList: React.FC = () => {
const { dataGridProps } = useDataGrid<IOperation>();
const operatorIds = dataGridProps.rows.map((item) => item.operatorId);
const { data: operatorsData, isLoading: operatorsIsLoading } =
useMany<IOperator>({
resource: "operators",
ids: operatorIds,
queryOptions: {
enabled: operatorIds.length > 0,
},
});
const columns = React.useMemo<GridColumns<IOperation>>(
() => [
{ field: "id", headerName: "ID", flex: 1, minWidth: 50 },
{ field: "name", headerName: "Name", flex: 1, minWidth: 350 },
{
field: "operatorId",
headerName: "Operator",
type: "number",
minWidth: 250,
flex: 1,
renderCell: function render({ row }) {
if (operatorsIsLoading) {
return "Loading...";
}
const operator = operatorsData?.data.find(
(item) => item.id === row.operatorId
);
return operator?.name;
},
},
{
headerName: "Actions",
field: "actions",
minWidth: 250,
renderCell: function render(params) {
return (
<Stack direction="row" spacing={1}>
<EditButton hideText recordItemId={params.row.id} />
<ShowButton hideText recordItemId={params.row.id} />
<DeleteButton hideText recordItemId={params.row.id} />
</Stack>
);
},
},
],
[
operatorsIsLoading,
operatorsData?.data,
]
);
return (
<List
cardHeaderProps={{
title: "Operations",
action: (
<Stack direction="row" spacing={1}>
<CreateButton />
<ExportButton onClick={triggerExport} loading={exportLoading} />
</Stack>
),
}}
>
<DataGrid
{...dataGridProps}
columns={columns}
autoHeight
checkboxSelection
disableSelectionOnClick
/>
</List>
);
};
With this configuration the filter of the column operatorId will be of type NUMBER so i can select <, >, != ecc. This works ok because the query to the backend use the id. Thanks! |
Beta Was this translation helpful? Give feedback.
Oh yes, i will try to explain better
This is my two table:
OPERATOR
OPERATIONS
This is the list component of the resource OPERATION