mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.04k stars 1.24k forks source link

[DataGridPro] Add context menu support #2873

Open m4theushw opened 2 years ago

m4theushw commented 2 years ago

Duplicates

Latest version

Summary 💡

Upvote this issue if you want it to be implemented natively.

While there's no built-in support, this demo shows how to add a context menu using componentsProps.row (it works in the free version too).

Examples 🌈

https://www.telerik.com/kendo-react-ui/knowledge-base/grid-context-menu/ https://ag-grid.com/javascript-grid-context-menu/ https://adazzle.github.io/react-data-grid/canary/?path=/story/demos--context-menu-story

Motivation 🔦

No response

Order ID 💳 (optional)

No response

xrawvelocity commented 2 years ago

Hello, I've been searching through here and the docs for a solution for this but when I tried to do what that example with componentProps.row showed for the free DataGrid it doesn't seem to work in the DataGridPro. I've also been looking for a detailed look of the componentProps but so far I haven't found it.

componentsProps={{
    row: {
        onContextMenu: (e) => {
            e.preventDefault()
            console.log('it did it')
        },
    },
}}

Nothing is being console logged so I wonder if anything is spelled differently or something

flaviendelangle commented 2 years ago

Could you give your version of the DataGrid please ? A reproduction case would be even better. This codesandbox.io template may be a good starting point. Thank you!

xrawvelocity commented 2 years ago

I have "@mui/x-data-grid-pro": "^4.0.0" Just tried replicating it in codesandbox and it gave me this error: Object literal may only specify known properties, and 'row' does not exist in type 'GridSlotsComponentsProps'

https://codesandbox.io/s/long-mountain-fisd1?file=/src/Demo.tsx

Thank you for the fast response btw

flaviendelangle commented 2 years ago

OK, you are probably looking at the v5 documentation Here is the doc for v4 : https://v4.mui.com/components/data-grid/getting-started/

m4theushw commented 2 years ago

@flaviendelangle The componentsProps.row and the context menu demo is only available in v5.

@xrawvelocity You need to update to v5 as this demo requires a newer API.

xrawvelocity commented 2 years ago

that was it. thank you, i didn't know this was part of the beta release

flaviendelangle commented 2 years ago

Yes that was my point, xrawvelocity is looking at v5 doc so he found a feature that was not available in v4.

harrycollin commented 2 years ago

Having something like this would be really useful

conerye commented 2 years ago

When I add a context menu to my datagrid using the componentsProps.row it causes the detail panel to cover table rows when expanded. Is this a known issue and if yes, is there a workaround? I need to have both a detail panel and right-click menu on my table... I am using "@mui/x-data-grid-premium": "^5.14.0"

m1daz commented 10 months ago

Im confused, is this a premium feature? I'm a pro plan user and I seem to not be able to get this onContextMenu thing working. mui-data-grid-pro 6.8

romgrk commented 10 months ago

You can look at the code of that example by clicking "Show code" and copy that code.

m1daz commented 10 months ago

You can look at the code of that example by clicking "Show code" and copy that code.

Nevermind, it was my fault.

I was typing

row: {
     onContextMenu: () => {}
}

in the slots={} prop and not in the slotsProps={} prop.