<ejs-grid
#Grid
...
@ViewChild('Grid')
Grid: GridComponent;
save() {
this.Grid.endEdit();
}
Regards,
Marko
|
let childgridObj = document.getElementById("Grid").ej2_instances[0]; //Child Grid instance
childgridObj.editModule.batchSave(); //calling the batchSave API
|
|
import { DetailRowService, GridModel, Grid } from '@syncfusion/ej2-ng-grids';
@Component({
selector: 'app-container',
template: ` <button id='show' ej-button class='e-flat' (click)='show()'> BatchSave </button>
<ejs-grid #grid [dataSource]='pData' height='265px' [childGrid]='childGrid' [showColumnChooser]= 'true'>
<e-columns>
<e-column field='City' headerText='City' width=150></e-column>
</e-columns>
</ejs-grid>
`,
providers: [DetailRowService]
})
export class AppComponent implements OnInit {
public childGrid: GridModel = {
queryString: 'EmployeeID',
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Batch', showConfirmDialog: false, },
toolbar: ['Edit', 'Update', 'Cancel'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', width: 120, isPrimaryKey: true },
]
};
ngOnInit(): void {
this.pData = employeeData;
}
show() {
// you can also get the child grid instances as like below
const childGridObj: Grid = (document.querySelector('.e-grid .e-grid') as any).ej2_instances[0];
childGridObj.editModule.batchSave(); // perform batchSave
}
}
|
|
@Component({
selector: 'app-container',
template: ` <button id='show' ej-button class='e-flat' (click)='show()'> BatchSave </button>
<ejs-grid #grid [dataSource]='pData' height='265px' [childGrid]='childGrid' [showColumnChooser]= 'true' [editSettings]='editSettings' [toolbar]='toolbar'>
<e-columns>
<e-column field='EmployeeID' headerText='Employee ID' textAlign='Right' isPrimaryKey='true'width=120></e-column>
</e-columns>
</ejs-grid>
`,
providers: [DetailRowService]
})
export class AppComponent implements OnInit {
public childGrid: GridModel = {
queryString: 'EmployeeID',
. . . . .
};
ngOnInit(): void {
this.pData = employeeData;
}
show() {
// get all the grid and perform the batchSave operation
for (let i = 0; i < document.querySelectorAll('.e-grid').length; i++) {
let gridObj: Grid = document.querySelectorAll('.e-grid')[i].ej2_instances[0].editModule.getBatchChanges();
// batchSave called only when perform CRUD operation (avoid duplicate request)
if (gridObj.addedRecords.length || gridObj.changedRecords.length || gridObj.deletedRecords.length) { // check whether grid has been edited
(document.querySelectorAll('.e-grid')[i] as any).ej2_instances[0].editModule.batchSave();
}
}
}
}
|
import { DetailRowService, GridModel, Grid } from '@syncfusion/ej2-ng-grids'; @Component({
selector: 'app-container',
template: ` .... <ej2-grid ...> <e-columns> .... <e-column field='isVerified' type='boolean'> <ng-template #template let-data> <ejs-checkbox #checkbox [checked]='data.isVerified' (change)='checkboxChange($event)'></ejs-checkbox> </ng-template> </e-column> .... `,
providers: [DetailRowService]
})
export class AppComponent implements OnInit { @ViewChild('grid') ... public grid: GridComponent; checkboxChange(args: ChangeEventArgs) { let currentRowObject: any = this.grid.getRowObjectFromUID(this.rowID); let currentRowData: Object = currentRowObject.data; currentRowData["isVerified"] = args.checked; this.grid.setCellValue(currentRowData["jobUid"], "isVerified", args.checked); currentRowObject.changes = currentRowData; } save() { var ch: any = (this.grid.editModule.getBatchChanges() as any).changedRecords.length; => always return 0?? ... } } |
|
...
@Component({
selector: 'app-container',
template: ` <button id='show' ej-button class='e-flat' (click)='save()'> BatchSave </button>
<ejs-grid #grid [dataSource]='data' height='265px' [editSettings]='editSettings' [toolbar]='toolbar'>
<e-columns>
...
<e-column field='Verified' type='boolean'>
<ng-template #template let-data>
<ejs-checkbox #checkbox [checked]='data.Verified' (change)='checkboxChange($event)'></ejs-checkbox>
</ng-template>
</e-column>
</e-columns>
</ejs-grid>
`,
providers: []
})
export class AppComponent implements OnInit {
...
checkboxChange(args: ChangeEventArgs) {
let currentRowObject: any = this.grid.getRowObjectFromUID(args.event.target.closest('tr').getAttribute('data-uid'));
let currentRowData: Object = currentRowObject.data;
//currentRowData["Verified"] = args.checked; //updating the datasource the changes so we will not get the changed records
//this.grid.setCellValue(currentRowData["jobUid"], "isVerified", args.checked); // setCellValue also saves the changes
let rowIndex: any = args.event.target.closest('td').getAttribute("index");
this.grid.editModule.updateCell(rowIndex, "Verified", args.checked); //so we updating the changes instead of saving it
}
save() {
var ch: any = (this.grid.editModule.getBatchChanges() as any).changedRecords.length; //Now you will get the changed records here
alert(ch);
}
ngOnInit(): void {
this.data = data,
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Batch', showConfirmDialog: false };
this.toolbar = ['Edit', 'Update', 'Cancel'];
}
} |
XXXXComponent.html:133 ERROR TypeError: Cannot read property 'index' of undefined at CellRenderer.evaluate (ej2-grids.es5.js:3918) at CellRenderer.refreshCell (ej2-grids.es5.js:4001) at CellRenderer.refreshTD (ej2-grids.es5.js:3967) at BatchEdit.refreshTD (ej2-grids.es5.js:20275) at BatchEdit.updateCell (ej2-grids.es5.js:20239) at Edit.updateCell (ej2-grids.es5.js:20652) at XXXXComponent.webpackJsonp.1132.XXXXComponent.checkboxChange (xxxx.component.ts:181) at Object.eval [as handleEvent] (XXXXComponent.html:133) at handleEvent (core.es5.js:12023) at callWithDebugContext (core.es5.js:13493) |
Can you help me to solve it? Thanks!
Timothy
| CellRenderer.prototype.evaluate = function (node, cell, data, attributes$$1, fData) { var result; if (cell.column.template) { var literals = ['index']; var dummyData = extend({}, data, (_a = {}, _a[foreignKeyData] = fData, _a)); result = cell.column.getColumnTemplate()(extend({ 'index': attributes$$1[literals[0]] }, dummyData), this.parent, 'template'); appendChildren(node, result); result = null; node.setAttribute('aria-label', node.innerText + ' is template cell' + ' column header ' + cell.column.headerText); return false; } return true; var _a; }; |
It seems that the parameter attributes$$1 is null. When I trace back the call stack, attributes$$1 comes from the highlighted function call.
| BatchEdit.prototype.refreshTD = function (td, column, rowObj, value) { var cell = new CellRenderer(this.parent, this.serviceLocator); this.setChanges(rowObj, column.field, value); var frzCols = this.parent.getFrozenColumns(); refreshForeignData(rowObj, this.parent.getForeignKeyColumns(), rowObj.changes); cell.refreshTD(td, rowObj.cells[this.getCellIdx(column.uid) - (this.getCellIdx(column.uid) >= frzCols ? frzCols : 0)], rowObj.changes); td.classList.add('e-updatedtd'); this.parent.notify(toolbarRefresh, {}); }; |
Here the highlighted call only pass 3 parameters to refreshTD but attributes$$1 is the forth parameter.
Can you help me to solve this? Thanks!