Hello,
We have this data structure:
0: id: 1
parentId: null
1: id: 2
parentId: 1
2: id: 3
parentId: 1
3: id: 4
parentId: 3
4: id: 5
parentId: 3
And want to use it in Grid with multiple
childGrids (Hierarchy grids). How can we do it? There is no common field value
like `queryString` (as in your demo - https://plnkr.co/edit/xJpipG882WCxUVcCs1IU?p=preview)
|
@Component({
selector: 'app-container',
template: `<ejs-grid #grid [dataSource]='pData' height='315px' [childGrid]='childGrid' (detailDataBound)='dataBound($event)'>
...
</ejs-grid>
`,
providers: [DetailRowService]
})
export class AppComponent implements OnInit {
public pData: Object[];
public childGrid: GridModel = {
detailDataBound: bound,
columns: [
...
], childGrid: {
columns: [
...
]
},
};
dataBound(args:any):void{
...
grid.query = new Query(); //Clear the query
grid.dataSource = data; //Provide your custom data here for first child
}
function bound(args:any):void{
...
grid.query = new Query(); //Clear the query
grid.dataSource = customerData; //Provide your custom data here for second child
}
} |
It is still unclear for me how I should make this in X level deep. I must make a universal grid where I don’t know how many childGrids there will be or what columns they will have. As I wrote previously, my data comes in one type of objects and each object has its own ID and parent ID (his parent in childGrid).
Its very simple and effective way to store hierarchic data:
'EmployeeID': 1,
'parentId': 1
'EmployeeID': 2,
'parentId': 2
'EmployeeID': 3,
'parentId': 1
'EmployeeID': 4,
'parentId': 1
Is it possible to use it in ChildGrid just as it is?
Thanks for
the demo (https://plnkr.co/edit/NfDux3wkhnLz032CRqzH?p=preview)
I will investigate it more, but it has a mistake – first childGrid pulls all
orders (not those orders that matches EmployeeID). Can you fix it? As it is
unclear how one should use `queryString` there.
Here I made
it working, by editing the Query, but as you see I must know how many
childGrids there will be. Could you advice how I can workaround this? In real
world I don’t know how man ChildGrids there will be.
DEMO - https://plnkr.co/edit/MVukfldXhbNkAVSqtGA1?p=preview
CODE:
// data example
//
'EmployeeID': 11,
// 'parentId': null,
// 'LastName': 'Finicuta',
// 'FirstName': 'Panda',
// 'Title': 'Sales Representative',
// 'TitleOfCourtesy': 'Ms.',
// 'BirthDate': new Date(-664743600000),
// 'HireDate': new Date(704692800000),
// 'Address': '507 - 20th Ave. E.\r\nApt. 2A',
// 'City': 'Seattle',
makeGrids(n)
{
while(n--) {
this.dataLoaders['bound' + n] = function(args:any):void{
var grid = args.detailElement.querySelector('.e-grid').ej2_instances[0];
grid.query = new Query();
var items = new DataManager(employeeData).executeLocal(new Query()
.where('parentId', 'equal',
args.data.EmployeeID));
grid.dataSource
= items;
}
return
{
detailDataBound: this.dataLoaders['bound' + n],
columns: [
{ field: 'parentId', headerText: 'parentId ID', textAlign: 'Right', width: 75
},
{ field: 'EmployeeID',
headerText: 'EmployeeID', width: 120 },
], childGrid: this.makeGrids(n)
}
}
}
ngOnInit():
void {
this.pData
= employeeData;
this.childGrid = {
detailDataBound:bound,
columns: [
{ field: 'parentId', headerText: 'parentId ID', textAlign: 'Right', width: 120
},
{ field: 'EmployeeID', headerText: 'Employee ID', width: 150 }
], childGrid: this.makeGrids(4)
};
}
dataBound(args:any):void{
var grid = args.detailElement.querySelector('.e-grid').ej2_instances[0];
grid.query = new Query();
var items = new DataManager(employeeData).executeLocal(new Query()
.where('parentId', 'equal', args.data.EmployeeID));
grid.dataSource
= items;
}
function bound(args:any):void{
var grid = args.detailElement.querySelector('.e-grid').ej2_instances[0];
grid.query = new Query();
var items = new DataManager(employeeData).executeLocal(new Query()
.where('parentId', 'equal',
args.data.EmployeeID));
grid.dataSource
= items;
}
Thanks for
answer The main issue with my solution is that I must know how many childGrids
there will be. But I think there isn’t much we can do here and a workaround is
to always pass the maximum number in `makeGrids()` (I picked 10, but I’m not
sure if this is a maximum number possible).
So this
issue is kinda solved, unless you think I can improve it somehow (you saw the
demo).
Thanks for
help!