I am currently utilizing the Material UI DataGrid element to display information from an EXCEL file. Each Excel document consists of numerous column titles with specific types assigned to them. As an example:
const columns = [
{
"field": "uwgroup",
"headerName": "Group",
"minWidth": 200,
"editable": true
},
{
"field": "Amazing column Name ",
"flex": 1,
"minWidth": 150,
"editable": true
},
{
"field": "Building TSI",
"type": 'number',
"flex": 1,
"minWidth": 150,
"editable": true
},
{
"field": "dev",
"flex": 1,
"minWidth": 150,
"editable": true
}
]
The column titled Building TSI
has been designated as a type number
. To highlight error cells, I have integrated the class name invalid
using cellClassName
, like so:
classnames({
invalid: !isPositiveNumber(params.value)
})
This implementation successfully enforces the class name and highlights any error cells. However, my current challenge involves counting the total number of error cells. This count is crucial as it dictates whether the grid values can be saved to the database, requiring there to be no errors present within any cells.
To address this issue, I have experimented with several solutions:
- Incorporating a state for
errorCount
and incrementing it each time a class is added. Nevertheless, this approach triggers multiple re-renders and surpasses the memory limit. - Utilizing
to determine the length of error cells. However, this method only applies to the items currently rendered on the page, presenting inaccuracies in the count for larger Excel files with pagination.document.getElementByClassNames('invalid')
- Exploring the use of the
preProcessEditCellProps
prop to indicate errors without identifying a way to retrieve the overall count of error cells. The main benefit is restricting users from entering incorrect values. - Experimenting with
localStorage
, which yields the same limitations as solution number 2 by solely evaluating the currently displayed page's content.
If anyone has encountered a similar scenario, I would greatly appreciate any insights. Having access to the cumulative error cells count would facilitate enabling or disabling the SAVE button accordingly.
One critical aspect to consider is the substantial size of the excel files, averaging between 30-40k rows and 25-40 columns. Managing state for individual cells could lead to performance issues.
Thank you in advance!