Skip to content

Commit

Permalink
[DataGridPremium] Fix size aggregation to ignore undefined values (
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Oct 23, 2023
1 parent ef93605 commit 5ccb1b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const maxAgg: GridAggregationFunction<number | Date> = {
columnTypes: ['number', 'date', 'dateTime'],
};

const sizeAgg: GridAggregationFunction<number> = {
const sizeAgg: GridAggregationFunction<unknown, number> = {
apply: ({ values }) => {
return values.length;
return values.filter((value) => typeof value !== 'undefined').length;
},
valueFormatter: (params: GridValueFormatterParams) => {
if (params.value == null || !isNumber(params.value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,5 +788,27 @@ describe('<DataGridPremium /> - Aggregation', () => {
).to.equal(45);
});
});

describe('`size`', () => {
it('should work with any value types', () => {
expect(
GRID_AGGREGATION_FUNCTIONS.size.apply({
values: [23, '', 'a', NaN, {}, false, true],
field: 'value',
groupId: 0,
}),
).to.equal(7);
});

it('should ignore undefined values', () => {
expect(
GRID_AGGREGATION_FUNCTIONS.size.apply({
values: [23, '', 'a', NaN, {}, false, true, undefined],
field: 'value',
groupId: 0,
}),
).to.equal(7);
});
});
});
});

0 comments on commit 5ccb1b1

Please sign in to comment.