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] Make value and colDef accessible in actions column #15667

Open
aress31 opened this issue Nov 29, 2024 · 5 comments
Open

[data grid] Make value and colDef accessible in actions column #15667

aress31 opened this issue Nov 29, 2024 · 5 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability new feature New feature or request status: waiting for author Issue with insufficient information

Comments

@aress31
Copy link

aress31 commented Nov 29, 2024

Summary

The params in getActions are only row, id and and columns; there is no information about the currently processed column or value which is quite restrictive when using type mappings. Addin them would improve DX and remove boilerplate code.

Examples

const getTypeMappings = (field) => ({
  // --- SNIP ---
  bytea: {
    headerName: undefined,
    type: "actions",
    getActions: ({ row }) => {
      const dataUrl = hexStringToDataUrl(row[field]);
      return [
        <GridActionsCellItem
          onClick={() => downloadFile(dataUrl)}
          icon={<Download />}
          label="Download"
          disabled={!dataUrl}
        />,
      ];
    },
  },
  // --- SNIP ---
});

Note: Also, transformations within valueGetter don't seem accessible to getActions too.

Motivation

Improve the DX and provide contextual info to getActions.

Search keywords: actions

@aress31 aress31 added new feature New feature or request status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 29, 2024
@michelengelen
Copy link
Member

Hey @aress31 ... why would you need a value or valueGetter in getActions? The actions col is a special column which purpose is simply to render a series of buttons that perform actions on the row in question. That's exactly why we pass the row as a property to it.

Could you explain your specific use case please?

@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information customization: extend Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 29, 2024
@michelengelen michelengelen changed the title [DataGridAction] Make value and colDef accessible [data grid] Make value and colDef accessible in actions column Nov 29, 2024
@aress31
Copy link
Author

aress31 commented Nov 29, 2024

@michelengelen simply because my action column need contextual information such as the current value/column name to process the action logic. See the code snippet in my opening message.

@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 Nov 29, 2024
@michelengelen
Copy link
Member

@michelengelen simply because my action column need contextual information such as the current value/column name to process the action logic. See the code snippet in my opening message.

I got that ... but how do you determine "current column"? Is it the selected one? Is it all of them? Without knowing this its hard to tell what you are trying to achieve.

You can always use the selectionModel to get the currently selected cell/row to process that. 🤷🏼

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 2, 2024
@aress31
Copy link
Author

aress31 commented Dec 2, 2024

@michelengelen I would just expect the getAction column to have access to the same prop than when calling renderCell, I would also expect the valueGetter transformation to also transform the value in the getAction.

@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 2, 2024
@michelengelen
Copy link
Member

But the actions column does not have any value that could be transformed by a valueGetter ... and why would it receive the same parameters as within the renderCell method? It's different by definition. There is a renderCell method present for the actions column as well.

If you really need the value form another column within the getActions you can use the apiRef to look for it. Again, if you want us to help you please explain the use case you have in more detail. There is a way to do that, but in order for us to come up with something we need to know! 🙇🏼

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 2, 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: extend Logic customizability new feature New feature or request status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

2 participants