Add record having child - problem
this.$refs.orders.ej2Instances.addRecord(items, 0)

Uncaught TypeError: Cannot read property 'parentItem' of undefined
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.localExpand (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3615)
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.expandCollapse (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3495)
at Observer.
at Observer.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-base/src/observer.js.Observer.notify (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-base_src_m.js:736)
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-base/src/base.js.Base.trigger (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_i.js:1276)
at VueComponent.push../node_modules/@syncfusion/ej2-vue-treegrid/src/treegrid/treegrid.component.js.TreeGridComponent.trigger ([email protected]:676)
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.collapseRow (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3307)
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.expandCollapseRequest (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3259)
at TreeGrid.push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.mouseClickHandler (chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:2669)
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.localExpand @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3615
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.expandCollapse @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3495
(anonymous) @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3309
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-base/src/observer.js.Observer.notify @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-base_src_m.js:736
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-base/src/base.js.Base.trigger @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_i.js:1276
push../node_modules/@syncfusion/ej2-vue-treegrid/src/treegrid/treegrid.component.js.TreeGridComponent.trigger @ [email protected]:676
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.collapseRow @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3307
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.expandCollapseRequest @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:3259
push../node_modules/@syncfusion/ej2-vue-treegrid/node_modules/@syncfusion/ej2-treegrid/src/treegrid/base/treegrid.js.TreeGrid.mouseClickHandler @ chunk-vendors~._node_modules_@syncfusion_ej2-vue-treegrid_node_modules_@syncfusion_ej2-treegrid_src_~e2257953.js:2669
<ejs-treegrid height="300" ref="orders" :dataSource="commodities" :editSettings="editSettings"
childMapping="children">
<e-columns>
<e-column width="240" field="cmdtyCd" headerText="품목" :template="eCommodityTemplate">e-column>
<e-column width="100" field="ordQty" headerText="수량" defaultValue="1">e-column>
<e-column width="100" field="" headerText="단위">e-column>
<e-column width="100" field="" headerText="총액">e-column>
e-columns>
ejs-treegrid>
// data section
editSettings: {
allowAdding: true,
allowEditing: true,
allowDeleting: true
},
commodities: []
addCommodities (items) {
if (items !== null && typeof items === 'object') {
console.log('Adding single item')
// this.$refs.orders.ej2Instances.addRecord(items, 0) // Doesn't work.
this.commodities.unshift(items)
this.$refs.orders.ej2Instances.refresh()
} else if (Array.isArray(items)) {
console.log('Adding array items')
items.forEach(o => {
this.commodities.unshift(o)
})
this.$refs.orders.ej2Instances.refresh()
} else {
// TODO error handling
}
recordDoubleClick (args) {
if (args.rowData.parentCmdtyCd) { // If rowData having parentCmdtyCd - skip
// Skip
console.log('Record double click - skip')
} else {
console.log('Record double click - call props', args.rowData)
// this.addCmdtyCd(args.rowData)
this.$emit('recordSelected', args.rowData) // Invoke record event to parent component, it will trigger addCommodities method
}
},
Query: Add record having child – problem
Based on your query, we've understood that you need to add a record from one treegrid to another treegrid. We suggest that you use Drag and Drop to drop a record to another treegrid. To use drag and drop between two treegrids, enable the enableRowDragAndDrop property and define the target TreeGrid ID in the targetID properties of rowDropSettings.
|
<template>
…
<div>
<ejs-treegrid id='TreeGrid' :dataSource="data" :allowRowDragAndDrop='true' height='315' :treeColumnIndex='1' :rowDropSettings='rowDrop' :selectionSettings='selectionSettings' childMapping='subtasks' >
<e-columns>
<e-column field="taskID" headerText="Task ID" width="120" isPrimaryKey="true"></e-column>
….
</ejs-treegrid>
<ejs-treegrid id='DestTree' :allowRowDragAndDrop='true' height='315' :treeColumnIndex='1' :rowDropSettings='rowDrops' :selectionSettings='selectionSettings' childMapping='subtasks' >
<e-columns>
<e-column field="taskID" headerText="Task ID" width="120" isPrimaryKey="true"></e-column>
….
</ejs-treegrid>
</div>
</div>
</template>
<script>
….
export default {
data() {
return {
data: dataSource,
selectionSettings: { type: 'Multiple' },
rowDrop: { targetID: 'DestTree' },
rowDrops: { targetID: 'TreeGrid' }
};
},
provide: {
treegrid: [RowDD, Selection]
}
}
</script>
|

this.$refs.orders.ej2Instances.addRecord(data, 0)
- In actionBegin event, with requestType as “save” for “edit” action, we have checked whether the edited record has child record and also checked whether the previous and current value of column are not same.
- Then we have set the changed column value to the child records and updating them by using the “updateRow” method by passing the index and changed record as parameters
- Thus on editing and saving parent column, the child records’s specific column value will also be updated as per your requirement.
|
actionBegin(args) {
let instance = this.$refs.treegrid.ej2Instances;
if (args.requestType === "save" && args.action === "edit") {
let hasChildren = instance.grid.dataSource[args.data.index].hasChildRecords;
// checking if the edited record has children
if ( hasChildren &&
args.previousData["taskName"] !== args.data["taskName"] ) { // here we have used
“taskName” column, similarly you can use your own column
for which you need to update child value based on parent edited value
var parentData = instance.grid.dataSource[args.data.index];
var childData = parentData.childRecords; //child records
- childRecords property have the collection of the children of parent record
for (let i = 0; i < childData.length; i++) {
let changedData = childData[i];
// changing specific column value of child
changedData["taskName"] = args.data["taskName"];
let childIndex = childData[i].index; // collecting child index
instance.updateRow(childIndex, changedData);
// updating the value of parent column to child by using updateRow method
by passing the index and data of child
}
}
}
},
|
toolbar: [
{
id: 'refresh',
text: 'Refresh'
},
'Delete'
],
|
<div>
<button @click="btnClick()">Add Record</button>
</div>
methods: {
btnClick: function (event) {
let instance = this.$refs.treegrid.ej2Instances;
instance.addRecord(
{
taskID: 501,
taskName: "test Child",
startDate: new Date(),
duration: 45,
},
1,
"Child"
); // pass data, index , newRowPosition
},
………
|
- 7 Replies
- 4 Participants
-
MI Minkyu
- Dec 2, 2020 01:49 AM UTC
- Dec 10, 2020 09:25 AM UTC