material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Actions passed as functions, when (selection: true), are ignore

Open LuisPinaSoares opened this issue 6 years ago • 2 comments

This problem has been documented before in #1662, #2039.

Basically when you have actions passed like this, with the selection: true option:

actions={[
  (rowData) => {
    console.log('rowdata', rowData);
    return {
      icon: tableIcons.Add,
      tooltip: 'Adicionar Substância ou Polímero',
      onClick: () => setDialog(true),
      position: 'row'
    }
  },
  {
    icon: tableIcons.Add,
    tooltip: 'Adicionar Substância ou Polímero',
    onClick: () => setDialog(true),
    position: 'row'
  }
]}

The action that is passed has a function is ignored, it does NOT appear in the table column actions. This invalidates conditional action rendering when selection: true.

LuisPinaSoares avatar Oct 04 '20 17:10 LuisPinaSoares

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Jan 02 '21 19:01 stale[bot]

@LuisPinaSoares actually it's not ignored, it just overrides the position and displays the action in the toolbar as found here #2696.

It seems like a bug to me, there is no reason why wouldn't take the position into account.

Thanks to the explanation in the issue #2696, I think this could do the trick. Instead of passing a function, give an object containing the action and a position property.

actions={[
  {
    action : (rowData) => {
      console.log('rowdata', rowData);
      return {
        icon: tableIcons.Add,
        tooltip: 'Adicionar Substância ou Polímero',
        onClick: () => setDialog(true),
      }
    },
    position : 'row'
  },
  {
    icon: tableIcons.Add,
    tooltip: 'Adicionar Substância ou Polímero',
    onClick: () => setDialog(true),
    position: 'row'
  }
]}

mrrenaud avatar Mar 22 '21 11:03 mrrenaud