I hope this message finds you well.
I'm writing to seek guidance regarding the utilization of the Syncfusion Spreadsheet component to manage complex structured data, including nested columns. Additionally, I need assistance with integrating CRUD (Create, Read, Update, Delete) API operations in this context.
While exploring the capabilities of the Spreadsheet component, I encountered a scenario where I'm required to render a complex object structure with nested columns. Alongside this, I'm aiming to implement CRUD operations to interact with the backend API seamlessly.
The data structure I'm working with involves nested arrays and objects, and I'm seeking guidance on effectively rendering this structure within the Spreadsheet. Moreover, I'll need to ensure that nested columns accurately represent the relationships between various objects and arrays.
To illustrate, here's a simplified example of the data structure I intend to populate:
REACT-JAVASCRIPT
Furthermore, the image I'm attaching exemplifies the desired outcome, particularly emphasizing the nested column structure within the Spreadsheet component. I am hoping to replicate this layout and behavior programmatically while maintaining the connections between nested columns and data elements.
Additionally, I'd greatly appreciate any insights, examples, or best practices that showcase how to seamlessly perform CRUD operations within this structured environment, allowing smooth interactions with the backend API.
Attached is the image depicting the desired nested column structure within the Spreadsheet component, which I aim to replicate programmatically.
Looking forward to your response and insights.
Hi Asad,
Regarding update data source:
Currently, spreadsheet does not support with updating the complex structure of data (nested column and array of nested column data) into it. You can be able to update the data to the spreadsheet as key-value object pair.
However, we have prepared a sample with reference to the screenshot attached. Attached the sample below for your reference.
Stackblitz Sample: https://stackblitz.com/edit/react-nlo53q-dpoczz?file=index.js,data.js
The below actions have been performed on the sample attached.
Using cell data binding:
We have updated the data directly to the <cell-directive> property along with the index position to update data.
Using updateCell method:
To update individual cell value you can use the updateCell method. The data updated via updateCell method are attached below.
Using updateRange method:
To update a data to a range of address you can use the updateRange method. Initially we have created a collection of data to be updated.
Using updateRange method updated those data to the sheet as expected. Attached screenshot for reference.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Regarding CRUD operations:
We have checked your requirement and the dataSourceChanged event handler will be triggered when editing, inserting, and deleting a row is made on the data source range. It is triggered with parameter named action which indicates edit, add, and delete for the respective action. By using this event you can do your customization in your end.
Stackblitz Sample: https://stackblitz.com/edit/react-cukmit-8plgsj?file=index.js
API Reference: https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/#datasourcechanged
Regarding storing the data:
We suspect that you need to update the data to the database and to retrieve it again to load into the spreadsheet. This can be done on the below possible ways.
Attached API links for reference.
https://ej2.syncfusion.com/angular/documentation/api/spreadsheet/#saveasjson
https://ej2.syncfusion.com/angular/documentation/api/spreadsheet/#openfromjson
Note: You can also use file import and export support available in spreadsheet. Instead, performing the customizations you can simply import the excel file into the spreadsheet with the customizations made and can save those data to the database.
https://ej2.syncfusion.com/react/documentation/spreadsheet/open-save
Attached links for reference.
UG Documentation
https://ej2.syncfusion.com/react/documentation/spreadsheet/getting-started
https://ej2.syncfusion.com/react/documentation/spreadsheet/data-binding
https://ej2.syncfusion.com/react/documentation/spreadsheet/editing
API Reference
https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/
https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/#updatecell
https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/#updaterange
https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/#setborder
https://helpej2.syncfusion.com/react/documentation/api/spreadsheet/#merge
Get back to us if you need any other further clarifications on this.