- Home
- Forum
- React - EJ 2
- Grid in inline-edit mode crashes when another component is rendered or state changes during editing.
Grid in inline-edit mode crashes when another component is rendered or state changes during editing.
"Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering."
- {requestType: "refresh", name: "actionBegin"}
- name: "beforeFragAppend"
- promise: undefined
- requestType: "refresh"
- rows: (4) [Row, Row, Row, Row]
- __proto__: Object
const [iconFileName, setIconFileName] = useState(null);
Regards,
Rajapandi R
- In line 66, where you define the "iconFileName" state variable, change it to
const [iconFileName, setIconFileName] = useState('Initial value');
so that we can assign a new value to the variable. - After line 32, where you define what happens once image upload is done, add the following line which will set the value of "iconFileName" state variable as the name of the file that was just uploaded:
setIconFileName(props.file.name);
What happens though, is that grid exits editing mode, and the following error is shown in Chrome's console:
|
function Home() {
const begin = (props: any) => { //actionBegin event of Grid
if (props.requestType === "save") {
props.data.Image = readString; //set the uploaded image string to the column field it helps to refresh the data and display the uploaded image in the template column
setIconFileName((document.getElementsByClassName('e-upload')[0] as any).nextElementSibling.innerText);
//change the state after updating the image data
}
}
const onUploadSuccess = (props: any) => {
//change the paragraph tag variable by using dom element
(document.getElementsByClassName('e-upload')[0] as any).nextElementSibling.innerText = props.file.name;
if(props.operation === 'upload') {
// Raw file of the uploaded image is retrieved
const file = props.file.rawFile;
// File reader is initialized and the raw file is read as URL
const reader = new FileReader();
reader.readAsDataURL(file);
// The base64 result is retrieved on load success
// This value is stored in global variable and returned in the read function of the cell edit template
reader.onload =() => {
console.log(reader.result);
readString = reader.result;
};
reader.onerror =(error: any) => {
console.log('Error: ', error);
};
}
};
const editTemplate = (props: any) => {
return (
<div>
<UploaderComponent id="uploader"
autoUpload={true}
multiple={false}
asyncSettings={uploadPath}
allowedExtensions='.png'
success={onUploadSuccess} />
<p>{iconFileName}</p>
</div>
);
};
const gridRef: any = useRef(null)
const [iconFileName, setIconFileName] = useState('Initial value');
const toolbarOptions: ToolbarItems[] = ["Add", "Edit", "Delete", "Cancel", "Search"];
const editOptions: EditSettingsModel = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Normal"
};
const pageSettings:PageSettingsModel = { pageSize: 6 };
return(<div> <p>Grid-1 using Functional Components</p>
<GridComponent dataSource={employeeData} ref={gridRef} allowPaging={true} pageSettings={ pageSettings }
editSettings={ editOptions } actionBegin={begin} toolbar={toolbarOptions} allowPdfExport={true} allowExcelExport={true} allowFiltering={true}>
<ColumnsDirective>
<ColumnDirective field='OrderID' isPrimaryKey={true} width='100' textAlign="Left"/>
<ColumnDirective field='CustomerID' width='100' textAlign="Left"/>
<ColumnDirective field='CustomerName' width='100' textAlign="Left"/>
<ColumnDirective field='Image' template={template} editTemplate={editTemplate} width='100' textAlign="Left"/>
</ColumnsDirective>
<Inject services={[Page, PdfExport, Filter, Group, Edit, ExcelExport, Search, Toolbar]} />
</GridComponent>
</div>
)
}
|
I have made a new thread discussing the issue in detail and have included an example app that demonstrates the issue.
|
Home.tsx
import { ColumnDirective, ColumnsDirective, GridComponent } from '@syncfusion/ej2-react-grids';
import { Edit, EditSettingsModel, ExcelExport, Filter, Group, Inject, Page,PageSettingsModel, PdfExport, Search, Toolbar, ToolbarItems} from '@syncfusion/ej2-react-grids';
import React, {useRef } from 'react';
import { employeeData } from './datasource';
import ComponentA from './Component1';
import { readString } from './Component1';
const template = (props: any) => {
const src = props.Image;
return (<div style={{ height: "55px", width: "55px"}}>
<img src={src} alt={props.Image} />
</div>);
};
function Home() {
const begin = (props: any) => {
if (props.requestType === "save") {
props.data.Image = readString;
}
}
const editTemplate = (props: any) => {
return (
<ComponentA />
);
};
const gridRef: any = useRef(null)
const toolbarOptions: ToolbarItems[] = ["Add", "Edit", "Delete", "Cancel", "Search"];
const editOptions: EditSettingsModel = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Normal"
};
const pageSettings:PageSettingsModel = { pageSize: 6 };
return(<div> <p>Grid-1 using Functional Components</p>
<GridComponent dataSource={employeeData} ref={gridRef} allowPaging={true} pageSettings={ pageSettings }
editSettings={ editOptions } actionBegin={begin} toolbar={toolbarOptions} allowPdfExport={true} allowExcelExport={true} allowFiltering={true}>
<ColumnsDirective>
<ColumnDirective field='OrderID' isPrimaryKey={true} width='100' textAlign="Left"/>
<ColumnDirective field='CustomerID' width='100' textAlign="Left"/>
<ColumnDirective field='CustomerName' width='100' textAlign="Left"/>
<ColumnDirective field='Image' template={template} editTemplate={editTemplate} width='100' textAlign="Left"/>
</ColumnsDirective>
<Inject services={[Page, PdfExport, Filter, Group, Edit, ExcelExport, Search, Toolbar]} />
</GridComponent>
</div>
)
}
export default Home;
|
|
Component1.tsx
import React, { memo, useState } from 'react';
import { UploaderComponent } from '@syncfusion/ej2-react-inputs';
export let readString: any = "";
const ComponentA = () => {
const [iconFileName, setIconFileName] = useState('Initial value');
const uploadPath: object = {
removeUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove',
saveUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save'
}
const onUploadSuccess = (props: any) => {
setIconFileName(props.file.name);
if(props.operation === 'upload') {
// Raw file of the uploaded image is retrieved
const file = props.file.rawFile;
// File reader is initialized and the raw file is read as URL
const reader = new FileReader();
reader.readAsDataURL(file);
// The base64 result is retrieved on load success
// This value is stored in global variable and returned in the read function of the cell edit template
reader.onload =() => {
console.log(reader.result);
readString = reader.result;
};
reader.onerror =(error: any) => {
console.log('Error: ', error);
};
}
};
return(
<div>
<UploaderComponent id="uploader"
autoUpload={true}
multiple={false}
asyncSettings={uploadPath}
allowedExtensions='.png'
success={onUploadSuccess} />
<p>{iconFileName}</p>
</div>
)
}
export default memo(ComponentA); //it helps to prevent the Grid from refresh |
Rajapandi R
Hi , I Am Facing the Same issue
when My SyncFusion
Following is code.
Attachment: Console_a767da5b.rar
Hi Ravi,
sorry for replaying late , here is the answers of your Queries
1) Please share your syncfusion package version.
2) Please share the issue replication procedure step by step.
i) Here Is my row (displaying single row) having custom validation Complete Code is given above Question
ii) Here is my Custom Validation
a)Constructor
iii) Custom control being rendered by Grid
and this is my cancel button ,
if my grid is edit mode (Say one row is edited state ) before closing this row(for example without pressing cancel or update button from toolbar of grid) .
I click on this cancel button (on form),which is navigating to another page the app crashes.
Note : this cancel button is present on form , this is not the syncfusion's toolbar Cancel button .
I am attaching the error picture .
any help would be highly appreciated.
Thank You.
Attachment: Console_a767da5b_140eda72.rar
- 15 Replies
- 4 Participants
- Marked answer
-
SP Spyros
- May 12, 2021 11:24 AM UTC
- Oct 25, 2021 01:29 PM UTC