Material-table: How Can I pass rowData to custom rendered switch's on change method

Created on 26 Feb 2019  路  3Comments  路  Source: mbrn/material-table

I have a custom rendered column in my table. I want to get rowData on change of that switch

image

Most helpful comment

@alyssonmessias This is how I was doing that (this method was being called inside render)

setColumns = (roles) => {
this.columns = []
this.columns.push({ title: 'DeviceId', field: 'id' })
this.columns.push({ title: 'Device Type', field: 'deviceType' })
this.columns.push({ title: 'Platform Id', field: 'platformId', hidden: true})
this.columns.push({ title: 'Primary Owner', field: 'primaryOwner' })
this.columns.push({ title: 'IsFree', field: 'isFree', hidden: true, searchable: false, render: rowData => {
return (
{rowData.isFree.toString()}
)
} })
this.columns.push({
title: 'IsDedicated', field: 'isDedicated', filtering: false, searchable: false, render: rowData => {
return (
disabled={!roles.changeDedicated}
checked={rowData.isDedicated}
onChange={(event) => {
this.handleChange(event, rowData)
}}
value={rowData.isDedicated}
/>
)
}
})
this.columns.push({
title: 'IsFaulty', field: 'isFaulty', hidden: true, searchable: false, render: rowData => {
return (
{rowData.isFaulty.toString()}
)
}
})
}

All 3 comments

I got the solution. I can get the rowData in render itself.

@priyankakumari1011 can you show example that how resolved this problem?
I have the same problem and I am not getting it to work, when the page changes it does not update the component.

@alyssonmessias This is how I was doing that (this method was being called inside render)

setColumns = (roles) => {
this.columns = []
this.columns.push({ title: 'DeviceId', field: 'id' })
this.columns.push({ title: 'Device Type', field: 'deviceType' })
this.columns.push({ title: 'Platform Id', field: 'platformId', hidden: true})
this.columns.push({ title: 'Primary Owner', field: 'primaryOwner' })
this.columns.push({ title: 'IsFree', field: 'isFree', hidden: true, searchable: false, render: rowData => {
return (
{rowData.isFree.toString()}
)
} })
this.columns.push({
title: 'IsDedicated', field: 'isDedicated', filtering: false, searchable: false, render: rowData => {
return (
disabled={!roles.changeDedicated}
checked={rowData.isDedicated}
onChange={(event) => {
this.handleChange(event, rowData)
}}
value={rowData.isDedicated}
/>
)
}
})
this.columns.push({
title: 'IsFaulty', field: 'isFaulty', hidden: true, searchable: false, render: rowData => {
return (
{rowData.isFaulty.toString()}
)
}
})
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

diegosps picture diegosps  路  3Comments

KKrisu picture KKrisu  路  3Comments

victorwvieira picture victorwvieira  路  3Comments

bohrsty picture bohrsty  路  3Comments

behrouz-s picture behrouz-s  路  3Comments