您好,我想在材料表上填写必填字段,但是 我无法实现这一点,请帮助,我确实阅读了一些论坛,其中说添加edicomponent并将必填内容作为html提交,但我不希望我使用此材料表库使必填字段像html表单一样。
谢谢。
function CustomEditComponent(props) {
const { useState } = React;
const [columns, setColumns] = useState([
{
title: 'Name', field: 'name',
editComponent: props => (
<input
type="text"
value={props.value}
onChange={e => props.onChange(e.target.value)}
required
/>
)
},
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
},
]);
const [data, setData] = useState([
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
{ name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
]);
return (
<MaterialTable
title="Custom Edit Component Preview"
columns={columns}
data={data}
editable={{
onRowAdd: newData =>
new Promise((resolve, reject) => {
setTimeout(() => {
setData([...data, newData]);
resolve();
}, 1000)
}),
onRowUpdate: (newData, oldData) =>
new Promise((resolve, reject) => {
setTimeout(() => {
const dataUpdate = [...data];
const index = oldData.tableData.id;
dataUpdate[index] = newData;
setData([...dataUpdate]);
resolve();
}, 1000)
}),
onRowDelete: oldData =>
new Promise((resolve, reject) => {
setTimeout(() => {
const dataDelete = [...data];
const index = oldData.tableData.id;
dataDelete.splice(index, 1);
setData([...dataDelete]);
resolve();
}, 1000)
}),
}}
/>
)
}