Something wrong with actions as functions with enabled selection (action as a function ignoring position props)
Describe the bug My mission is add new action to table (where selection is true) and show this action only with condition. As a result I can not see my button. Table settings:
padding: 'dense',
actionsColumnIndex: -1,
...
selection: true,
Actions:
(rowData) => ({
icon: LockIcon,
tooltip: 'Do smth',
position: 'row',
hidden: false,
onClick: (e, rowData) => {console.log('do something')}
}),
And there is no action until I turned off selection.
If I will remove rowData => ({...my_action}) and make action as object, everything start working again.
To Reproduce Steps to reproduce the behavior:
- Set table selection to true
- Add action as a function (as in example in Conditionals Actions Example here https://material-table.com/#/docs/features/actions)
- Profit, you not able to see your action
Expected behavior We should able to see action button as a row action
Versions: "material-table": "^1.57.2", "@material-ui/core": "4.9.2", "@material-ui/icons": "4.9.1", "@material-ui/lab": "^4.0.0-alpha.42", "@material-ui/styles": "^4.9.0", "react": "^16.9.0",
Any ideas?
P.S. I forked main branch and see the same behavior in demo.
Ok, I think that problem in /src/material-table.js on rows 125-138. For some reason if we using actions as a function and selection in parent table, we set position for current action as 'toolbarOnSelect' instead of 'row'. I not sure that I understand why we doing this and what logic author wanna use here. @mbrn can you give me idea what are you wanna see here?
On local I am using for fix:
if (typeof action === "function") return { action: action, position: action().position ? action().position : "toolbarOnSelect" };
In /src/material-table.js on row 132
+1
I was able to get this to work - see here for more details
I just wanna confirm that @oze4 PR resolve this problem. But its a kind of hammer and not a scalpel. The strange behavior still here.
I have been looking at this and i can confirm what @scipe is mentioning. When you have something like this for actions:
actions={[
(rowData) => {
console.log('rowdata', rowData);
return {
icon: tableIcons.Steps,
tooltip: 'Stuuuuffffff',
onClick: () => setDialog(true),
position: 'row'
}
},
{
icon: tableIcons.Add,
tooltip: 'Stuuuuffffff',
onClick: () => setDialog(true),
position: 'row'
}
]}
only the action element in the actions array that is not a function will be displayed.
Which is a problem because it implies that you cannot have conditional action rendering with selection: true option.