Skip to content

Commit 0555a17

Browse files
authored
Merge pull request #8827 from IgniteUI/mtsvyatkova/fix-8786-master
Apply formatter in summaries
2 parents bf55f26 + db3bcc2 commit 0555a17

12 files changed

+230
-78
lines changed

CHANGELOG.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes for each version of this project will be documented in this
44

55
## 12.0.0
66

7+
### General
8+
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
9+
- **Breaking Change** - The `locale` and `pipeArgs` parameters are removed from the `operate` method exposed by the `IgxNumberSummaryOperand`, `IgxDateSummaryOperand`, `IgxCurrencySummaryOperand` and `IgxPercentSummaryOperand`. They are now set in the `igx-grid-summary-cell` template. To change the locale and format setting of the `igx-grid-summary-cell` the user can use the new `summaryFormatter` property of the `IgxColumnComponent`.
10+
711
### New Features
812
- `IgxForOf`, `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
913
- **Behavioral Change** - Virtual containers now scroll smoothly when using the mouse wheel(s) to scroll them horizontally or vertically. This behavior more closely resembles the scrolling behavior of non-virtualized containers in most modern browsers.
@@ -16,11 +20,28 @@ All notable changes for each version of this project will be documented in this
1620
</ng-template>
1721
</igx-grid>
1822
```
23+
- A new `summaryFormatter` input property is exposed by the `IgxColumnComponent`, which is used to format the displayed summary values for the columns.
24+
```typescript
25+
public dateSummaryFormat(summary: IgxSummaryResult, summaryOperand: IgxSummaryOperand): string {
26+
const result = summary.summaryResult;
27+
if(summaryOperand instanceof IgxDateSummaryOperand && summary.key !== 'count'
28+
&& result !== null && result !== undefined) {
29+
const pipe = new DatePipe('en-US');
30+
return pipe.transform(result,'MMM YYYY');
31+
}
32+
return result;
33+
}
34+
```
35+
```html
36+
<igx-column field="OrderDate" header="Order Date" [sortable]="true" [disableHiding]="true" [dataType]="'date'" [hasSummary]="true"
37+
[summaryFormatter]="dateSummaryFormat">
38+
</igx-column>
39+
```
1940
### Themes:
2041
- Breaking Changes:
2142
- `IgxButton` theme has been simplified. The number of theme params (`igx-button-theme`) has been reduced significantly and no longer includes prefixed parameters (`flat-*`, `raised-*`, etc.). See the migration guide to update existing button themes. Updates performed with `ng update` will migrate existing button themes but some additional tweaking may be required to account for the abscense of prefixed params.
2243
- The `igx-typography` mixin is no longer implicitly included with `igx-core`. To use our typography styles users have to include the mixin explicitly:
23-
44+
2445
```html
2546
@include igx-core();
2647
/// Example with Indigo Design theme:
@@ -48,10 +69,10 @@ All notable changes for each version of this project will be documented in this
4869
- Added support for exporting grouped data.
4970
- `IgxTreeGrid`
5071
- Added `multipleCascade` row selection mode. In this mode, selecting a record results in the selection of all its children recursively. When only some children are selected, their parent's checkbox is in an indeterminate state.
51-
72+
5273

5374
```html
54-
<igx-tree-grid [rowSelection]="'multipleCascade'">
75+
<igx-tree-grid [rowSelection]="'multipleCascade'">
5576
</igx-tree-grid>
5677
```
5778
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
@@ -65,7 +86,7 @@ All notable changes for each version of this project will be documented in this
6586
- `Column Resizing` now does not exit edit mode.
6687
- `IgxInput` now supports `type="file"` and its styling upon all themes.
6788
_Note: validation of file type input is not yet supported._
68-
- `igxSplitter` now has the following additional outputs:
89+
- `igxSplitter` now has the following additional outputs:
6990
- `resizeStart` - Emits when pane resizing starts.
7091
- `resizing`- Emits while panes are being resized.
7192
- `resizeEnd` - Emits when pane resizing ends.

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { IgxGridFilteringCellComponent } from '../filtering/base/grid-filtering-
3636
import { IgxGridHeaderGroupComponent } from '../headers/grid-header-group.component';
3737
import { getNodeSizeViaRange } from '../../core/utils';
3838
import { IgxSummaryOperand, IgxNumberSummaryOperand, IgxDateSummaryOperand,
39-
IgxCurrencySummaryOperand, IgxPercentSummaryOperand } from '../summaries/grid-summary';
39+
IgxCurrencySummaryOperand, IgxPercentSummaryOperand, IgxSummaryResult } from '../summaries/grid-summary';
4040
import {
4141
IgxCellTemplateDirective,
4242
IgxCellHeaderTemplateDirective,
@@ -575,6 +575,37 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
575575
@WatchColumnChanges()
576576
@Input()
577577
public formatter: (value: any) => any;
578+
579+
/**
580+
* The summaryFormatter is used to format the display of the column summaries.
581+
*
582+
* In this example, we check to see if the column name is OrderDate, and then provide a method as the summaryFormatter
583+
* to change the locale for the dates to 'fr-FR'. The summaries with the count key are skipped so they are displayed as numbers.
584+
*
585+
* ```typescript
586+
* onColumnInit(column: IgxColumnComponent) {
587+
* if (column.field == "OrderDate") {
588+
* column.summaryFormatter = this.summaryFormat;
589+
* }
590+
* }
591+
*
592+
* summaryFormat(summary: IgxSummaryResult, summaryOperand: IgxSummaryOperand): string {
593+
* const result = summary.summaryResult;
594+
* if(summaryResult.key !== 'count' && result !== null && result !== undefined) {
595+
* const pipe = new DatePipe('fr-FR');
596+
* return pipe.transform(result,'mediumDate');
597+
* }
598+
* return result;
599+
* }
600+
* ```
601+
*
602+
* @memberof IgxColumnComponent
603+
*/
604+
@notifyChanges()
605+
@WatchColumnChanges()
606+
@Input()
607+
public summaryFormatter: (summary: IgxSummaryResult, summaryOperand: IgxSummaryOperand) => any;
608+
578609
/**
579610
* Sets/gets whether the column filtering should be case sensitive.
580611
* Default value is `true`.

projects/igniteui-angular/src/lib/grids/common/grid-pipes.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
IgxStringReplacePipe,
1818
IgxGridTransactionStatePipe,
1919
IgxColumnFormatterPipe,
20+
IgxSummaryFormatterPipe,
2021
IgxGridAddRowPipe
2122
} from './pipes';
2223

@@ -38,7 +39,8 @@ import {
3839
IgxStringReplacePipe,
3940
IgxGridTransactionStatePipe,
4041
IgxGridAddRowPipe,
41-
IgxColumnFormatterPipe
42+
IgxColumnFormatterPipe,
43+
IgxSummaryFormatterPipe
4244
],
4345
exports: [
4446
IgxGridFilterConditionPipe,
@@ -57,7 +59,8 @@ import {
5759
IgxStringReplacePipe,
5860
IgxGridTransactionStatePipe,
5961
IgxGridAddRowPipe,
60-
IgxColumnFormatterPipe
62+
IgxColumnFormatterPipe,
63+
IgxSummaryFormatterPipe
6164
],
6265
imports: [
6366
CommonModule

projects/igniteui-angular/src/lib/grids/common/pipes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GridType } from './grid.interface';
77
import { IgxColumnComponent } from '../columns/column.component';
88
import { ColumnDisplayOrder } from './enums';
99
import { IgxColumnActionsComponent } from '../column-actions/column-actions.component';
10+
import { IgxSummaryOperand, IgxSummaryResult } from '../grid/public_api';
1011

1112
/**
1213
* @hidden
@@ -308,6 +309,15 @@ export class IgxColumnFormatterPipe implements PipeTransform {
308309
}
309310
}
310311

312+
@Pipe({ name: 'summaryFormatter' })
313+
export class IgxSummaryFormatterPipe implements PipeTransform {
314+
315+
transform(summaryResult: IgxSummaryResult, summaryOperand: IgxSummaryOperand,
316+
summaryFormatter: (s: IgxSummaryResult, o: IgxSummaryOperand) => any) {
317+
return summaryFormatter(summaryResult, summaryOperand);
318+
}
319+
}
320+
311321
@Pipe({
312322
name: 'gridAddRow',
313323
pure: true

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

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { GridSummaryCalculationMode } from '../common/enums';
2727
import { IgxNumberFilteringOperand, IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
2828
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
2929
import { DropPosition } from '../moving/moving.service';
30+
import { DatePipe } from '@angular/common';
3031

3132
describe('IgxGrid - Summaries #grid', () => {
3233
configureTestSuite();
@@ -194,14 +195,14 @@ describe('IgxGrid - Summaries #grid', () => {
194195
fixture.detectChanges();
195196

196197
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
197-
['10', '0', '20,000', '39,004', '3,900.4', '6']);
198+
['10', '0', '20000', '39004', '3900.4', '6']);
198199
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']);
199200

200201
grid.getCellByColumn(4, 'InStock').update(true);
201202
fixture.detectChanges();
202203

203204
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
204-
['10', '0', '20,000', '39,004', '3,900.4', '7']);
205+
['10', '0', '20000', '39004', '3900.4', '7']);
205206

206207
grid.filter('UnitsInStock', 0, IgxNumberFilteringOperand.instance().condition('equals'));
207208
fixture.detectChanges();
@@ -258,7 +259,7 @@ describe('IgxGrid - Summaries #grid', () => {
258259
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 2,
259260
['Count', 'Min', 'Max', 'Sum', 'Avg'], ['8', '1', '1,000', '2,204', '275.5']);
260261
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count'], ['8']);
261-
const options = { year: 'numeric', month: 'short', day: 'numeric' };
262+
const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', day: 'numeric' };
262263
const earliest = SampleTestData.timeGenerator.timedelta(SampleTestData.today, 'month', -1).toLocaleString('us', options);
263264
const latest = SampleTestData.timeGenerator.timedelta(SampleTestData.today, 'month', 1).toLocaleString('us', options);
264265
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Count', 'Earliest', 'Latest'], ['8', earliest, latest]);
@@ -352,14 +353,14 @@ describe('IgxGrid - Summaries #grid', () => {
352353
const summaryClass = fix.componentInstance.numberSummary;
353354

354355
const summaries = summaryClass.operate(fix.componentInstance.data.map((x) => x['UnitsInStock']));
355-
expect(summaries[0].summaryResult).toBe('10');
356-
expect(summaries[1].summaryResult).toBe('0');
357-
expect(summaries[2].summaryResult).toBe('20,000');
358-
expect(summaries[3].summaryResult).toBe('39,004');
359-
expect(summaries[4].summaryResult).toBe('3,900.4');
356+
expect(summaries[0].summaryResult).toBe(10);
357+
expect(summaries[1].summaryResult).toBe(0);
358+
expect(summaries[2].summaryResult).toBe(20000);
359+
expect(summaries[3].summaryResult).toBe(39004);
360+
expect(summaries[4].summaryResult).toBe(3900.4);
360361

361362
const emptySummaries = summaryClass.operate();
362-
expect(emptySummaries[0].summaryResult).toBe('0');
363+
expect(emptySummaries[0].summaryResult).toBe(0);
363364
expect(typeof emptySummaries[1].summaryResult).not.toEqual(undefined);
364365
expect(typeof emptySummaries[2].summaryResult).not.toEqual(undefined);
365366
expect(typeof emptySummaries[3].summaryResult).not.toEqual(undefined);
@@ -370,25 +371,48 @@ describe('IgxGrid - Summaries #grid', () => {
370371
expect(typeof emptySummaries[3].summaryResult).not.toEqual(null);
371372
expect(typeof emptySummaries[4].summaryResult).not.toEqual(null);
372373

373-
expect(emptySummaries[1].summaryResult === '0').toBeTruthy();
374-
expect(emptySummaries[2].summaryResult === '0').toBeTruthy();
375-
expect(emptySummaries[3].summaryResult === '0').toBeTruthy();
376-
expect(emptySummaries[4].summaryResult === '0').toBeTruthy();
374+
expect(emptySummaries[1].summaryResult === 0).toBeTruthy();
375+
expect(emptySummaries[2].summaryResult === 0).toBeTruthy();
376+
expect(emptySummaries[3].summaryResult === 0).toBeTruthy();
377+
expect(emptySummaries[4].summaryResult === 0).toBeTruthy();
377378
});
378379

379380

380381
it('should calculate summaries for \'date\' dataType or return if no data is provided', () => {
381382
const summaryClass = fix.componentInstance.dateSummary;
383+
const pipe = new DatePipe('en-US');
382384

383385
const summaries = summaryClass.operate(fix.componentInstance.data.map((x) => x['OrderDate']));
384-
expect(summaries[0].summaryResult).toBe('10');
385-
expect(summaries[1].summaryResult.trim()).toBe('May 17, 1990');
386-
expect(summaries[2].summaryResult.trim()).toBe('Dec 25, 2025');
386+
expect(summaries[0].summaryResult).toBe(10);
387+
expect(pipe.transform(summaries[1].summaryResult, 'mediumDate')).toBe('May 17, 1990');
388+
expect(pipe.transform(summaries[2].summaryResult, 'mediumDate')).toBe('Dec 25, 2025');
387389

388390
const emptySummaries = summaryClass.operate([]);
389-
expect(emptySummaries[0].summaryResult).toBe('0');
390-
expect(emptySummaries[1].summaryResult).toBe(null);
391-
expect(emptySummaries[2].summaryResult).toBe(null);
391+
expect(emptySummaries[0].summaryResult).toBe(0);
392+
expect(emptySummaries[1].summaryResult).toBe(undefined);
393+
expect(emptySummaries[2].summaryResult).toBe(undefined);
394+
});
395+
396+
it('should display summaries for \'date\' dataType based on column formatter', () => {
397+
const summaryRow = GridSummaryFunctions.getRootSummaryRow(fix);
398+
const pipe = new DatePipe('fr-FR');
399+
400+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4,
401+
['Count', 'Earliest', 'Latest'], ['10', 'May 17, 1990', 'Dec 25, 2025']);
402+
403+
grid.getColumnByName('OrderDate').summaryFormatter
404+
= ((summaryResult: IgxSummaryResult, summaryOperand: IgxSummaryOperand) => {
405+
const result = summaryResult.summaryResult;
406+
if(summaryOperand instanceof IgxDateSummaryOperand
407+
&& summaryResult.key !== 'count' && result !== null && result !== undefined) {
408+
return pipe.transform(result,'mediumDate');
409+
}
410+
return result;
411+
});
412+
fix.detectChanges();
413+
414+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4,
415+
['Count', 'Earliest', 'Latest'], ['10', '17 mai 1990', '25 déc. 2025']);
392416
});
393417

394418
it('should calc tfoot height according number of summary functions', () => {
@@ -959,7 +983,7 @@ describe('IgxGrid - Summaries #grid', () => {
959983
GridSummaryFunctions.verifySummaryCellActive(fix, 3, 0);
960984

961985
const summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 3);
962-
let summaryCell = GridSummaryFunctions.getSummaryCellByVisibleIndex(summaryRow, 0);
986+
const summaryCell = GridSummaryFunctions.getSummaryCellByVisibleIndex(summaryRow, 0);
963987
GridFunctions.simulateGridContentKeydown(fix, 'ArrowDown');
964988
fix.detectChanges();
965989

@@ -983,7 +1007,7 @@ describe('IgxGrid - Summaries #grid', () => {
9831007

9841008
GridSummaryFunctions.verifySummaryCellActive(fix, 3, 1);
9851009

986-
summaryCell = GridSummaryFunctions.getSummaryCellByVisibleIndex(summaryRow, 1);
1010+
// summaryCell = GridSummaryFunctions.getSummaryCellByVisibleIndex(summaryRow, 1);
9871011
GridFunctions.simulateGridContentKeydown(fix, 'ArrowUp');
9881012
fix.detectChanges();
9891013
cell = grid.getCellByColumn(2, 'ParentID');

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,11 @@ describe('IgxGrid Component Tests #grid', () => {
15491549
});
15501550

15511551
grid.locale = 'de-DE';
1552+
grid.columnList.toArray()[5].pipeArgs = {
1553+
timezone: 'UTC',
1554+
format: 'longDate',
1555+
digitsInfo: '1.2-2'
1556+
};
15521557
grid.columnList.toArray()[4].pipeArgs = {
15531558
timezone: 'UTC',
15541559
format: 'longDate',

0 commit comments

Comments
 (0)