Material-table: How to render custom components on editable table and enable editing only on edit action click ?

Created on 16 Oct 2019  路  4Comments  路  Source: mbrn/material-table

I'm using material-table in a project. There I need to render a custom editable components. As an example I need to render a custom dropdown list. However I was able to to it with render option under the columns . But I can't figure out how to make this editable only on editable action click. Because now, this is always editable. So, how can I make this readonly and edit only on _edit_ action click

  const columns = [
 {
      title: intl.formatMessage({ ...messages.rateType }),
      lookup: StaticLookup.baseAccountTypes,
      field: 'configType',
      render: rowData => (
        <Select
          id="configType"
          className={classes.formControlTopMarginAdjustment}
          option={StaticLookup.configTypes}
          optionId="key"
          optionName="value"
          value={rowData.configType}
          dataAutoId={RATE_CONFIG_LIST('configType')}
        />
      ),
    },,
]

Any help would be appreciated.
Thanks

ask to stackoverflow question

Most helpful comment

Check out the editComponent prop:

 const columns = [
 {
      title: intl.formatMessage({ ...messages.rateType }),
      lookup: StaticLookup.baseAccountTypes,
      field: 'configType',
      editComponent: tableData => (
        <Select
          id="configType"
          className={classes.formControlTopMarginAdjustment}
          option={StaticLookup.configTypes}
          optionId="key"
          optionName="value"
          value={tableData.rowData.configType}
          dataAutoId={RATE_CONFIG_LIST('configType')}
        />
      ),
    },
]

All 4 comments

Check out the editComponent prop:

 const columns = [
 {
      title: intl.formatMessage({ ...messages.rateType }),
      lookup: StaticLookup.baseAccountTypes,
      field: 'configType',
      editComponent: tableData => (
        <Select
          id="configType"
          className={classes.formControlTopMarginAdjustment}
          option={StaticLookup.configTypes}
          optionId="key"
          optionName="value"
          value={tableData.rowData.configType}
          dataAutoId={RATE_CONFIG_LIST('configType')}
        />
      ),
    },
]

Thanks @josh-feldman . I was able to do it using this. However I have a scenario I need to display different data (on a same column) conditionally, and edit it. I was able to render it on edit, conditionally using editComponent prop. But having trouble to display it conditionally and edit it using onChange. Is there any way I can do it ?

as an example,

(if tableData.rowData.configType === 'A')
    return tableData.rowData.a;
return tableData.rowData.b

How can I make this work ?

@thidasapankaja
I encourage you to ask material-table related questions on StackOverflow, so that others could benefit from them as well.

ok Thanks @jayarjo .
Btw, I was able to get this work after I asked the question in Stackoverflow and mentioned in the chat group. This is it.

https://stackoverflow.com/questions/58431036/how-to-edit-multiple-fields-in-single-column-material-table

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlgreene2 picture jlgreene2  路  3Comments

roseak picture roseak  路  3Comments

lazeebee picture lazeebee  路  3Comments

ModPhoenix picture ModPhoenix  路  3Comments

balibou picture balibou  路  3Comments