Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I customize filter options in MUI data grid filter #2007

Open
vinitaran opened this issue Jun 22, 2023 · 1 comment
Open

How can I customize filter options in MUI data grid filter #2007

vinitaran opened this issue Jun 22, 2023 · 1 comment

Comments

@vinitaran
Copy link

I have a field to bookmark rows and the filter to that column is a boolean type. So the filter displays the value true or false but instead I want it to display Marked or Unmarked. How can I do that?

const columns: GridColDef[] = [
{
field: "watchlist",
headerName: "Wishlist",
width: 120,
type: "boolean",
renderCell: (params) => (


<CustomCheckbox
rowId={params.id}
columnId={params.field}
checked={params.value}
onCheckboxClick={() =>
handleCheckboxClick(params.row.project_id, params.value)
}
/>

),
},
]

Screenshot 2023-06-22 at 09 34 05
@jordan-kaxig
Copy link

I solved it by using type: "singleSelect" instead of type: "boolean". For "singleSelect" types, you can define which value options you want. And also you could set the filterOperators to only hold the "is" operator.

So you would do:

import { getGridSingleSelectOperators } from "@mui/x-data-grid-pro";

const columns: GridColDef[] = [
  {
    field: "watchlist",
    headerName: "Wishlist",
    width: 120,
    type: "singleSelect",
    valueOptions: [
      { value: true, label: "Marked" },
      { value: false, label: "Unmarked" },
    ],
    filterOperators: getGridSingleSelectOperators().filter((operator) => operator.value === "is"),
    renderCell: (params) => (
      <CustomCheckbox
        rowId={params.id}
        columnId={params.field}
        checked={params.value}
        onCheckboxClick={() =>
          handleCheckboxClick(params.row.project_id, params.value)
        }
      />
    ),
  },
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants