Hi,
I am using this link to create crontextmenu https://www.syncfusion.com/kb/12296/how-to-add-record-with-dynamic-newrowposition-using-context-menu and add rows in my grid:
after implementing this my Cell Saved and Cell Edit event is not triggering.
Also, initially after adding the rows in my grid. I was not able to add values in Cell. After edit it just vanished. however to resolve this i have implemented Refresh grid method. which allows me to add rows as well as allows me to update values which Cell can retain and does not vanish. But I have following issues which i am not able to solve
If you can please provide me a sample with below:
const totalChildPoint= function (field:any, data:any, column:any) {
Additional information. I have tried using following code. that also does not work, there is something about the "Mode" which is not allowing rows to be added into tree grid.
|
App.Component.html:-
<div class="control-section">
<ejs-treegrid #treegrid
[dataSource]="data"
childMapping="subtasks"
height="350"
[treeColumnIndex]="1"
id="treegridcomp"
allowPaging="true"
[pageSettings]="pageSettings"
allowExcelExport="true"
allowPdfExport="true"
[allowSelection]="true"
[selectionSettings]="selectionOptions"
allowSorting="true"
(contextMenuOpen)="contextMenuOpen($event)"
(contextMenuClick)="contextMenuClick($event)"
[contextMenuItems]="contextMenuItems"
[editSettings]="editing"
[toolbar]="toolbar"
(actionBegin)="actionBegin($event)"
(actionComplete)="actionComplete($event)">
<e-columns>
. . .
<e-column field="progress"
headerText="Progress"
width="90"
textAlign="Right"
[edit]="editparams"
[valueAccessor]="totalChildValue"
editType="numericedit"></e-column>
</e-columns>
</ejs-treegrid>
</div>
App.Component.ts
export class AppComponent {
public data: Object[] = [];
public pageSettings: Object;
public contextMenuItems: Object;
public editing: EditSettingsModel;
@ViewChild('treegrid')
public treeGridObj: TreeGridComponent;
ngOnInit(): void {
this.data = sampleData;
this.contextMenuItems = [
{
text: 'Add Child',
target: '.e-content',
id: 'addchildrow',
iconCss: ' e-icons e-circle-add',
cssClass: 'e-flat',
},
];
this.selectionOptions = {
type: 'Single',
mode: 'Row',
};
(this.editing = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
newRowPosition: 'Top',
showConfirmDialog: false,
mode: 'Row',
}),
(this.pageSettings = { pageSize: 11 });
this.editparams = { params: { format: 'n' } };
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
}
contextMenuOpen(args): void {
this.rowIndex = args.rowInfo.rowIndex;
this.cellIndex = args.rowInfo.cellIndex;
}
totalChildValue(field, data, column) {
if (isNullOrUndefined(data.parentItem)) {
let totalUnitWeight = 0;
data.subtasks.map((row) => (totalUnitWeight += row['progress']));
return totalUnitWeight;
}
return data.progress;
}
actionComplete(args) {
if (args.requestType == 'save') {
this.treeGridObj.refresh(); //refresh the TreeGrid upon saving while adding new child and newly added value has been added into aggregate
}
}
actionBegin(args) {
if (args.requestType == 'beginEdit' && args.rowData.hasChildRecords) {
args.cancel = true; //prevent editing for parent records
}
}
contextMenuClick(args): void {
var i = 100;
var data = {
taskID: i + 1,
taskName: 'test',
progress: 100,
};
var treegridInst = this.treeGridObj;
var selectedRecord = this.selectedRecord;
if (args.item.id === 'addchildrow') {
this.treeGridObj.addRecord(data, this.rowIndex, 'Child'); //add child row on custom contextmenu item
}
}
} |