Material-table: Add feature: disable action depending on row data

Created on 21 Jan 2019  路  3Comments  路  Source: mbrn/material-table

I have noticed that we can only declare an action disabled with true/false :

actions = [
    {
      icon: "arrow_upward",
      disabled: true,
      onClick: (e, row) => this.handleUp(e, row)
    }
]

I would like to disable it depending on a condition on the row data, something like this :

actions = [
    {
      icon: "arrow_upward",
      tooltip: "Move up",
      disabled: row => row.tableData.id === 0,
      onClick: (e, row) => this.handleUp(e, row)
    }
]

Is it possible ?

Thank you very much.

help wanted

Most helpful comment

Yes it is possible to return action data completely according to rowData:

actions = [
    rowData => ({
      icon: "arrow_upward",
      tooltip: "Move up",
      disabled: rowData => rowData.tableData.id === 0,
      onClick: (e, row) => this.handleUp(e, row)
    })
]

Look at this:
https://mbrn.github.io/material-table/#/docz-examples-03-example-actions
More Actions 2.icon

All 3 comments

Yes it is possible to return action data completely according to rowData:

actions = [
    rowData => ({
      icon: "arrow_upward",
      tooltip: "Move up",
      disabled: rowData => rowData.tableData.id === 0,
      onClick: (e, row) => this.handleUp(e, row)
    })
]

Look at this:
https://mbrn.github.io/material-table/#/docz-examples-03-example-actions
More Actions 2.icon

Thank you !
I forgot about this.
It solves my problem so this feature I proposed is not needed I think.

There are something wrong in the code. it's not correct to put function in the disabled property.
So the correct code is in the below.

actions = [
    rowData => ({
      icon: "arrow_upward",
      tooltip: "Move up",
      disabled: rowData.tableData.id === 0,
      onClick: (e, row) => this.handleUp(e, row)
    })
]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bohrsty picture bohrsty  路  3Comments

lazeebee picture lazeebee  路  3Comments

revskill10 picture revskill10  路  3Comments

roseak picture roseak  路  3Comments

behrouz-s picture behrouz-s  路  3Comments