[英]How to edit multiple fields in single column material-table
我正在為一個項目使用材料表。 我有一個場景,我需要有條件地在單個列中呈現和編輯多個字段。
這是場景
{
title: intl.formatMessage({ ...commonMessages.rate }),
field: 'fixed',
render: rowData => {
if (rowData.config === 'A') {
if (rowData.type !== 'B') {
return (
<Fragment>
<Typography variant="body1">
Pips : {rowData.pips}
</Typography>
<Typography variant="body1">
Percentage : {rowData.percentage}
</Typography>
</Fragment>
);
}
return (
<Typography variant="body1">
{rowData.percentage}
</Typography>
);
}
return (
<Typography variant="body1">{rowData.fixed}</Typography>
);
},
editComponent: props => {
if (props.rowData.type === 'A') {
if (props.rowData.type !== 'B') {
return (
<Fragment>
<Grid item xs={12} sm={12} md={12} lg={6}>
<TextField
id="pips"
onChange={e => props.onChange(e.target.value)}
value={props.rowData.pips}
/>
</Grid>
<Grid item xs={12} sm={12} md={12} lg={6}>
<TextField
id="percentage"
onChange={e => props.onChange(e.target.value)}
value={props.rowData.percentage}
/>
</Grid>
</Fragment>
);
}
return (
<TextField
id="fixed"
onChange={e => props.onChange(e.target.value)}
value={props.rowData.fixed}
/>
);
}
此處渲染和編輯組件正確顯示。 但是由於該字段是'fixed'
,因此點數和百分比的值不會改變,因為 onChange 適用於fixed
,即使列中的任何其他值發生了變化。
我怎樣才能解決這個問題? 任何幫助,將不勝感激。 謝謝
您可以像這樣使用onRowDataChange
道具:
<TextField
id="pips"
onChange={e =>
props.onRowDataChange({
...props.rowData,
pips: e.target.value
})
}
value={props.rowData.pips}
/>
這是一個代碼筆。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.