Skip to content

Commit 1e4b689

Browse files
authored
Merge pull request #1183 from IgniteUI/skrastev/fix-data-export
fix(tree-grid): Fix Data Exporting sample data generation.
2 parents 99da66a + 0b110e9 commit 1e4b689

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

  • samples/grids/tree-grid/data-exporting-indicator/src

samples/grids/tree-grid/data-exporting-indicator/src/index.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IgcGridToolbarComponent, IgcTreeGridComponent } from 'igniteui-webcomponents-grids/grids';
22
import { defineComponents, IgcButtonComponent } from 'igniteui-webcomponents';
3-
import { OrdersTreeData } from './OrdersData';
3+
import { OrdersTreeData, OrdersTreeDataItem } from './OrdersData';
44
import 'igniteui-webcomponents-grids/grids/combined';
55
import 'igniteui-webcomponents-grids/grids/themes/light/bootstrap.css';
66

@@ -10,15 +10,8 @@ defineComponents(IgcButtonComponent);
1010
export class Sample {
1111

1212
constructor() {
13-
const localData: any[] = [];
14-
for (let i = 0; i < 10000; i += 3) {
15-
for (let c = 0; c < this.ordersTreeData.length; c++) {
16-
localData.push(this.ordersTreeData[c]);
17-
}
18-
}
19-
2013
var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
21-
treeGrid.data = localData;
14+
treeGrid.data = this.generateData();
2215

2316
var toolbar = document.getElementById('toolbar') as IgcGridToolbarComponent;
2417
var button = document.getElementById('simulate') as IgcButtonComponent;
@@ -38,6 +31,45 @@ export class Sample {
3831
}
3932
return this._ordersTreeData;
4033
}
34+
35+
36+
generateData() {
37+
const localData: OrdersTreeDataItem[] = [];
38+
for (let i = 1; i < 10000; i += 1) {
39+
40+
const randomId = 1 + Math.floor(Math.random() * 3);
41+
let childRows: OrdersTreeDataItem[] = [];
42+
let childIndex = 0;
43+
for (let c = 0; c < this.ordersTreeData.length; c ++) {
44+
const item = this.ordersTreeData[c];
45+
if (item.ParentID == -1 || !item.ID.toString().startsWith(randomId.toString())) {
46+
continue;
47+
}
48+
childRows.push({
49+
...item,
50+
ID: parseInt(`${i}0${childIndex}`),
51+
ParentID: i,
52+
});
53+
childIndex++;
54+
}
55+
56+
localData.push({
57+
ID: i,
58+
ParentID: -1,
59+
Name: `Oder ${i}`,
60+
Category: '',
61+
Units: childRows.map(row => row.Units).reduce((prev, curr) => prev + curr, 0),
62+
Price: childRows.map(row => row.UnitPrice).reduce((prev, curr) => prev + curr, 0),
63+
UnitPrice: Math.random() * 1000,
64+
OrderDate: '',
65+
Delivered: Math.floor(Math.random()) ? true : false,
66+
67+
});
68+
localData.push(...childRows);
69+
}
70+
71+
return localData;
72+
}
4173
}
4274

4375
new Sample();

0 commit comments

Comments
 (0)