This is the code of my table.
const [columns, setColumns] = useState([
{ title: 'S.No', field: 'S_No_Format', editable: 'never'},
{ title: 'Date', field: 'Date_Format', type : 'date', sorting: false },
{ title: 'Description', field: 'Description', sorting: false ,validate: rowData => rowData.Description === '' || rowData.Description === undefined ? { isValid: false, helperText: 'Invalid Description' } : true },
{ title: 'Hours', field: 'Hours', type: 'numeric', sorting: false ,validate: rowData => rowData.Hours === '' || rowData.Hours === undefined || rowData.Hours < 0 ? { isValid: false, helperText: 'Invalid Hours' } : true},
]);
const [DataArray , setDataArray] = useState([]);
return (
<React.Fragment>
<Navbar />
<div>
<MaterialTable
title="Timesheet"
columns={columns}
data={DataArray}
icons={tableIcons}
editable={{
onRowAddCancelled: rowData => console.log('Row adding cancelled'),
onRowUpdateCancelled: rowData => console.log('Row editing cancelled'),
onRowAdd: newData =>
new Promise((resolve, reject) => {
setTimeout(() => {
newData.Date_Format = Date_To_Regular(newData.Date_Format);
console.log(newData)
resolve();
}, 1000);
})
}}
options={{
actionsColumnIndex: -1,
search:false,
exportButton: true,
}}
/>
</div>
</React.Fragment>
);
I want to validate the date while adding a new row. The date selected should either be today , yesterday or day before. How do I validate the date?