[HTML]
<ej-treegrid id="TreeGridControl" [dataSource]="treeGridData [selectedRowIndex]="selectedRowIndex" (actionComplete) ="actionComplete($event) >
...
</ej-treegrid>
<button (click)=" loadData(1)">ChangeDatasource</button> |
[TS]
export class AppComponent {
public treeGridData: any = {};
public datasource: any = {};
public selectedRowIndex: any;
public constructor(){
this.datasource = [{
//..
}]
this.selectedRowIndex = 4;
}
public loadData( selectRow?: number) {
this.datasource = this.loadSomeData();
if( selectRow != null) {
this.selectedRowIndex = selectRow;
}
}
public loadSomeData(){
this.treeGridData = [{
//..
}]
return this.treeGridData;
}
// Event trigger while changing datasource dynamically.
actionComplete(args){
if(args.requestType == "refreshDataSource"){
//code to done after the dynamic change of datasource.
}
}
} |
Hello Suriyaprasanth R.,
it seems like I'm doing something wrong.
I want to implement the following use case:
My problem:
Case 1: I load the data an immidiatly I call my Function
in this case the function return -1 because the currentViewData is empty.
Case 2: I call the function searchRowForId() in actionComplete and try to select the node there
-> the same result currentViewData is empty.
Any ideas?
searchRowForId(id: number): number {
var treeObj = $('#TreeGridControl').ejTreeGrid("instance")
var dataRow = treeObj.model.updatedRecords;
let rowIdx = -1;
for (let i = 0; i < dataRow.length; ++i) {
if (dataRow[i].taskID === id) {
rowIdx = i;
break;
}
}
return rowIdx;
} |
Hi,
the issue still exists. I modified the example. Please turn on the console output, I added some output where the issue occurs.
The use case: I press the button to load new data and want to select a sub-node.
Internally I search for the row index, then I try to expand the parent-nodes if necessary and then I select the node.
[TS]
public selectRow: any;
public constructor() {
this.datasource = dataSet1;
this.selectedRowIndex = 4;
}
public loadData(selectRow?: number) {
this.datasource = this.loadSomeData();
this.selectRow = selectRow;
}
public loadSomeData() {
return dataSet2;
}
// Event trigger while changing datasource dynamically.
actionComplete(args) {
// code to done after the dynamic change of datasource.
if (args.requestType === 'refreshDataSource') {
if (this.selectRow != null) {
let rowIndex = this.searchRowForId(this.selectRow);
this.expandParentNodes(rowIndex);
const treeObj = $('#TreeGridControl').ejTreeGrid('instance');
treeObj.model.selectedRowIndex = rowIndex;
}
}
} |
Hi,
it works - thank you ....