I am using a Grid which has a ChildGrid both with inline edit mode.
With "this.grid.addRecord()", I can add a new row in the Parent Grid from my .ts file.
I wish I could also add a record to the Child Grid with the addRecord() function indicating the index of the Parent Row.
How can I do?
Thanks
Yes, my requirement is to add a new data to the child Grid immediately after adding a data to the parent Grid
|
// Parent Grid’s actionComplete event handler
actionComplete(args) {
if (args.requestType === 'save' && args.action === 'add') {
// The queryString field value(that establishes the relation between parent and child row) is added to the new child data
var employeeIdVal = args.data['EmployeeID'];
// A unique primary key value is generated for the new child data
var primaryKeyVal = parseInt((Math.random() * 1000).toString());
// Child data object is formed
var newDat = { EmployeeID: employeeIdVal, OrderID: primaryKeyVal, ... };
// The new child data is pushed to the childGrid’s dataSource property
this.gridObj.childGrid.dataSource.push(newDat);
}
} |
You set newDat manually from code. I want that after save parenRow, his childGrid action begin "Edit" for the user to create childRow
Thanks
Hi,
No, my requirement is add a new row of childgrid from .ts file. In this stackblitz, the onClick() function I add a record in my parentGrid.
The same thing I would like to do for childGrid.
Specifying the Parent Row, I would like to execute the addRecord function for Child Grid
https://stackblitz.com/edit/angular-yvt5sx-5cmkir?file=app.component.ts
|
// Button click event function
addChildRecord() {
// The parent row of index – 0 is expanded
this.gridObj.detailRowModule.expand(0);
setTimeout(function () {
// The expanded parent row element is retrieved using its index
var parentRow = this.gridObj.getRowByIndex(0);
// The child Grid will be rendered as the parent row’s next sibling element
// So using this the child Grid instance is retrieved
var childGridInst = parentRow.nextElementSibling.querySelector('.e-grid').ej2_instances[0];
// Now a new record is added to the child Grid
childGridInst.addRecord();
}.bind(this), 100);
} |