Skip to content

Commit 77bbb70

Browse files
authored
Merge pull request #10683 from IgniteUI/mkirova/fix-10662
fix(pivot): Fix issue with key value being overriden with original re…
2 parents 039d48c + d1b56d7 commit 77bbb70

File tree

2 files changed

+117
-3
lines changed

2 files changed

+117
-3
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IgxPivotNumericAggregate } from './pivot-grid-aggregate';
66
import { IPivotConfiguration } from './pivot-grid.interface';
77
import { IgxPivotColumnPipe, IgxPivotRowExpansionPipe, IgxPivotRowPipe } from './pivot-grid.pipes';
88
import { PivotGridFunctions } from '../../test-utils/pivot-grid-functions.spec';
9+
import { DATA } from 'src/app/shared/pivot-data';
910

1011
describe('Pivot pipes #pivotGrid', () => {
1112
let rowPipe: IgxPivotRowPipe;
@@ -1532,4 +1533,117 @@ describe('Pivot pipes #pivotGrid', () => {
15321533
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', Country: 'USA', SellerName: 'John' }
15331534
]);
15341535
});
1536+
// automation for https://github.com/IgniteUI/igniteui-angular/issues/10545
1537+
it('should generate last dimension values for all records.', () => {
1538+
data = [
1539+
{
1540+
ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley',
1541+
Country: 'Bulgaria', City: 'Sofia', Date: '01/01/2021', UnitsSold: 282
1542+
},
1543+
{
1544+
ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa',
1545+
Country: 'USA', City: 'New York', Date: '01/05/2019', UnitsSold: 296
1546+
},
1547+
{
1548+
ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia',
1549+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '01/06/2020', UnitsSold: 68
1550+
},
1551+
{
1552+
ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David',
1553+
Country: 'USA', City: 'New York', Date: '04/07/2021', UnitsSold: 293
1554+
},
1555+
{
1556+
ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John',
1557+
Country: 'USA', City: 'New York', Date: '12/08/2021', UnitsSold: 240
1558+
},
1559+
{
1560+
ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry',
1561+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '05/12/2020', UnitsSold: 456
1562+
},
1563+
{
1564+
ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter',
1565+
Country: 'Bulgaria', City: 'Plovdiv', Date: '02/19/2020', UnitsSold: 492
1566+
}];
1567+
pivotConfig.columns = [{
1568+
memberName: 'Country',
1569+
enabled: true
1570+
}];
1571+
pivotConfig.rows = [
1572+
new IgxPivotDateDimension(
1573+
{
1574+
memberName: 'Date',
1575+
enabled: true
1576+
},
1577+
{
1578+
months: false
1579+
}
1580+
),
1581+
{
1582+
memberName: 'City',
1583+
enabled: true
1584+
},
1585+
{
1586+
memberFunction: () => 'All',
1587+
memberName: 'AllProducts',
1588+
enabled: true,
1589+
childLevel: {
1590+
memberFunction: (recData) => recData.ProductCategory,
1591+
memberName: 'ProductCategory',
1592+
enabled: true
1593+
}
1594+
},
1595+
{
1596+
memberName: 'SellerName',
1597+
enabled: true
1598+
}
1599+
];
1600+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1601+
const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1602+
const rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1603+
const sellers = rowStatePipeResult.map(x => x.SellerName);
1604+
// there should be no empty values.
1605+
expect(sellers.filter(x => x === undefined).length).toBe(0);
1606+
});
1607+
1608+
// automation for https://github.com/IgniteUI/igniteui-angular/issues/10662
1609+
it('should retain processed values for last dimension when bound to complex object.', () => {
1610+
data = DATA;
1611+
pivotConfig.rows = [
1612+
{
1613+
memberName: 'Date',
1614+
enabled: true,
1615+
},
1616+
{
1617+
memberName: 'AllProduct',
1618+
memberFunction: () => 'All Products',
1619+
enabled: true,
1620+
childLevel:
1621+
{
1622+
1623+
memberName: 'Product',
1624+
memberFunction: (recData) => recData.Product.Name,
1625+
enabled: true
1626+
}
1627+
},
1628+
{
1629+
memberName: 'AllSeller',
1630+
memberFunction: () => 'All Sellers',
1631+
enabled: true,
1632+
childLevel:
1633+
{
1634+
memberName: 'Seller',
1635+
memberFunction: (recData) => recData.Seller.Name,
1636+
enabled: true,
1637+
},
1638+
},
1639+
];
1640+
1641+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1642+
const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1643+
const rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1644+
1645+
const res = rowStatePipeResult.filter(x => x.AllSeller === undefined).map(x => x.Seller);
1646+
// all values should be strings as the result of the processed member function is string.
1647+
expect(res.filter(x => typeof x !== 'string').length).toBe(0);
1648+
});
15351649
});

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export class PivotUtil {
307307
const flatData = [];
308308
hierarchies.forEach((h, key) => {
309309
const field = h.dimension.memberName;
310+
const keys = Object.assign({}, pivotKeys) as any;
310311
let obj = {};
311312
obj[field] = key;
312313
if (h[pivotKeys.records]) {
@@ -322,16 +323,15 @@ export class PivotUtil {
322323
for (const nested of nestedData) {
323324
if (nested[pivotKeys.records] && nested[pivotKeys.records].length === 1) {
324325
// only 1 child record, apply same props to parent.
325-
const keys = Object.assign({}, pivotKeys) as any;
326326
const memberName = h[pivotKeys.children].entries().next().value[1].dimension.memberName;
327-
keys[memberName] = nested[memberName];
327+
keys[memberName] = memberName;
328328
PivotUtil.processSiblingProperties(nested[pivotKeys.records][0], [nested], keys);
329329
}
330330
}
331331
obj[pivotKeys.records] = this.getDirectLeafs(nestedData, pivotKeys);
332332
obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records] = nestedData;
333333
if (!rootData) {
334-
PivotUtil.processSiblingProperties(rec, obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records], pivotKeys);
334+
PivotUtil.processSiblingProperties(rec, obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records], keys);
335335
}
336336
}
337337
});

0 commit comments

Comments
 (0)