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

[data grid] Triple clicking to edit boolean column type in datagrid #15838

Open
zdonner100 opened this issue Dec 10, 2024 · 3 comments
Open

[data grid] Triple clicking to edit boolean column type in datagrid #15838

zdonner100 opened this issue Dec 10, 2024 · 3 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability enhancement This is not a bug, nor a new feature feature: Editing Related to the data grid Editing feature

Comments

@zdonner100
Copy link

zdonner100 commented Dec 10, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/embed/4slft7?module=/src/Demo.tsx&fontsize=12
  2. Set editable to true for 'isAdmin' column
    3.Expect boolean column type to be a checkbox accessible by single click but you have to double click in to edit it.

Current behavior

Have to triple click in order to change boolean value checkbox.

Expected behavior

A single click should change a boolean column from true to false and vice versa.

Context

Editing boolean column types effectively.

Your environment

System:
OS: Windows 10 10.0.19045
Binaries:
Node: 18.20.3 - C:\Program Files\nodejs\node.EXE
npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
pnpm: Not Found
Browsers:
Chrome: Not Found
Edge: Chromium (131.0.2903.70)
npmPackages:
@emotion/react: ^11.13.0 => 11.13.3
@emotion/styled: ^11.13.0 => 11.13.0
@mui/base: 5.0.0-beta.60
@mui/core-downloads-tracker: 5.16.7
@mui/icons-material: ^5.16.5 => 5.16.7
@mui/material: ^5.16.5 => 5.16.7
@mui/material-nextjs: ^5.15.11 => 5.16.6
@mui/private-theming: 5.16.6
@mui/styled-engine: 5.16.6
@mui/system: 5.16.7
@mui/types: 7.2.18
@mui/utils: 5.16.6
@mui/x-data-grid: 7.22.0
@mui/x-data-grid-premium: ^7.7.1 => 7.22.0
@mui/x-data-grid-pro: 7.22.0
@mui/x-date-pickers: ^6.16.3 => 6.20.2
@mui/x-internals: 7.21.0
@mui/x-license: ^7.7.1 => 7.21.0
@types/react: 18.3.3 => 18.3.3
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.0 => 18.3.1
typescript: ^5.4.5 => 5.6.3

Search keywords: boolean column type editing

Search keywords:

@zdonner100 zdonner100 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 10, 2024
@mj12albert mj12albert transferred this issue from mui/material-ui Dec 11, 2024
@mj12albert mj12albert added the component: data grid This is the name of the generic UI component, not the React module! label Dec 11, 2024
@michelengelen michelengelen changed the title Triple clicking to edit boolean column type in datagrid [data grid] Triple clicking to edit boolean column type in datagrid Dec 11, 2024
@michelengelen
Copy link
Member

Hey @zdonner100 ... this is by design. You can change that behavior though if you apply a custom cell renderer:

{
  field: 'isAdmin',
  type: 'boolean',
  width: 120,
  editable: true,
  renderCell: ({ row, api, value }) => (
    <Switch
      onClick={(event) => {
        // stop propagation to prevent row selection
        event.stopPropagation();
        // change value here
        api.updateRows([{ ...row, isAdmin: !value }]);
        console.log('click');
      }}
      checked={value}
    />
  ),
},

Would that solve your use case?

@michelengelen michelengelen added status: waiting for author Issue with insufficient information feature: Editing Related to the data grid Editing feature customization: logic Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 11, 2024
@zdonner100
Copy link
Author

Hi @michelengelen,

Yes, this does solve my use case but I am hesitant to standardize our boolean column around a custom renderCell.
2 questions...

  1. Are there enhancements to the boolean column type on the horizon? Triple clicking to edit a checkbox field is an ux problem that our business users put in a bug for, it would be much better if this was just a simple checkbox by default (similar to the built in checkbox column)
  2. If not, is there a way to make this change globally so that all of our boolean type columns are rendered the same by default without having to repeat renderCell in each use?

Thanks,

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Dec 11, 2024
@michelengelen
Copy link
Member

Hi @michelengelen,

Yes, this does solve my use case but I am hesitant to standardize our boolean column around a custom renderCell. 2 questions...

  1. Are there enhancements to the boolean column type on the horizon? Triple clicking to edit a checkbox field is an ux problem that our business users put in a bug for, it would be much better if this was just a simple checkbox by default (similar to the built in checkbox column)

Not that I am aware of. I will treat this issue as a feature request and add it to the board. Maybe we can introduce something like new slots, or props to provide a global override for the standard cell renderer.

  1. If not, is there a way to make this change globally so that all of our boolean type columns are rendered the same by default without having to repeat renderCell in each use?

One thing that you can do is to build a custom colDef with all the basic settings you typically have on a boolean col and then spread it wherever needed.

It could look something like this:

import { GRID_BOOLEAN_COL_DEF } from '@mui/x-data-grid';

// ...

const CUSTOM_BOOLEAN_COL_DEF = {
  ...GRID_BOOLEAN_COL_DEF
  type: 'boolean',
  display: 'flex',
  align: 'center',
  headerAlign: 'center',
  renderCell: renderCustomBooleanCell,
}

// in your column definition you can then use it as always

const columns = [
  {
    // other columns
  },
  {
    ...CUSTOM_BOOLEAN_COL_DEF,
    // any other overrides here
  },
]:

Would this be sufficient for now?

@michelengelen michelengelen added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 13, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability enhancement This is not a bug, nor a new feature feature: Editing Related to the data grid Editing feature
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

3 participants