Skip to content

Commit 23be00c

Browse files
authored
Merge pull request #8251 from IgniteUI/use-ngDateDecimalPipes-master
Use default Angular Date and Decimal Pipe, localize grid summaries
2 parents 614dfd0 + 4a75e4a commit 23be00c

31 files changed

+474
-183
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ All notable changes for each version of this project will be documented in this
4848
- `cellEditExit` is a new event that fires when cell exits edit mode
4949
- `rowEditExit` is a new event that fires when row exits edit mode
5050
- Added *getRowData(rowSelector)* method that returns an object that represents the data that is contained in the specified row component.
51-
- Added ability to spawn row adding UI through exoposed methods. Note that rowEditing should be enabled.
51+
- Added ability to spawn row adding UI through exposed methods. Note that rowEditing should be enabled.
5252
- `beginAddRow` method which starts the adding row UI.
5353
- `beginAddChild` method which starts the adding child UI.
5454
```typescript
@@ -63,6 +63,22 @@ All notable changes for each version of this project will be documented in this
6363
</igx-action-strip>
6464
</igx-tree-grid>
6565
```
66+
- A new `locale` and `pipeArgs` parameters are introduced in the `operate` method exposed by the `IgxNumberSummaryOperand` and `IgxDateSummaryOperand`, which exposes the grid locale. Use the `locale` parameter to get localized summary data (as per the grid locale. If not passed, `locale` defaults to `'en-US'`). Use the `pipeArgs` parameter only if you want to customize the format of the date and numeric values that will be returned.
67+
```typescript
68+
class MySummary extends IgxDateSummaryOperand {
69+
operate(columnData: any[], allData = [], fieldName, locale: string, pipeArgs: IColumnPipeArgs): IgxSummaryResult[] {
70+
const pipeArgs: IColumnPipeArgs = {
71+
format: 'longDate',
72+
timezone: 'UTC',
73+
digitsInfo: '1.1-2'
74+
}
75+
const result = super.operate(columnData, allData, fieldName, locale, pipeArgs);
76+
return result;
77+
}
78+
}
79+
```
80+
- A new `pipeArgs` input property is exposed by the `IgxColumnComponent`, which is used to pass arguments to the Angular `DatePipe` and `DecimalPipe`, to format the display for date and numeric columns.
81+
```typescript
6682
- ` IGX_INPUT_GROUP_TYPE` injection token
6783
- Allows for setting an input group `type` on a global level, so all input-group instances, including components using such an instance as a template will have their input group type set to the one specified by the token. It can be overridden on a component level by explicitly setting a `type`.
6884
- ` IgxExcelExporterService`

projects/igniteui-angular/src/lib/grids/cell.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
formatter
2020
? (value | columnFormatter: formatter)
2121
: column.dataType === 'number'
22-
? (value | igxdecimal: grid.locale)
22+
? (value | number:column.pipeArgs.digitsInfo:grid.locale)
2323
: column.dataType === 'date'
24-
? (value | igxdate: grid.locale)
24+
? (value | date:column.pipeArgs.format:column.pipeArgs.timezone:grid.locale)
2525
: value
2626
"
2727
[row]="rowData"
@@ -32,9 +32,9 @@
3232
formatter
3333
? (value | columnFormatter: formatter)
3434
: column.dataType === "number"
35-
? (value | igxdecimal: grid.locale)
35+
? (value | number:column.pipeArgs.digitsInfo:grid.locale)
3636
: column.dataType === "date"
37-
? (value | igxdate: grid.locale)
37+
? (value | date:column.pipeArgs.format:column.pipeArgs.timezone:grid.locale)
3838
: column.dataType === "boolean"
3939
? ""
4040
: value
@@ -50,7 +50,7 @@
5050
[cssClass]="highlightClass"
5151
[activeCssClass]="activeHighlightClass"
5252
[groupName]="gridID"
53-
[value]="formatter ? (value | columnFormatter:formatter) : column.dataType === 'number' ? (value | igxdecimal: grid.locale) : column.dataType === 'date' ? (value | igxdate: grid.locale) : value"
53+
[value]="formatter ? (value | columnFormatter:formatter) : column.dataType === 'number' ? (value | number:column.pipeArgs.digitsInfo:grid.locale) : column.dataType === 'date' ? (value | date:column.pipeArgs.format:column.pipeArgs.timezone:grid.locale) : value"
5454
[row]="rowData"
5555
[column]="this.column.field"
5656
[containerClass]="'igx-grid__td-text'"

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ import {
4343
IgxCollapsibleIndicatorTemplateDirective,
4444
IgxFilterCellTemplateDirective
4545
} from './templates.directive';
46-
import { MRLResizeColumnInfo, MRLColumnSizeInfo } from './interfaces';
46+
import { MRLResizeColumnInfo, MRLColumnSizeInfo, IColumnPipeArgs } from './interfaces';
4747
import { DropPosition } from '../moving/moving.service';
4848
import { IgxColumnGroupComponent } from './column-group.component';
4949

50+
const DEFAULT_DATE_FORMAT = 'mediumDate';
51+
const DEFAULT_DIGITS_INFO = '1.0-3';
52+
5053
/**
5154
* **Ignite UI for Angular Column** -
5255
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid.html#columns-configuration)
@@ -1187,6 +1190,37 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
11871190
return this._visibleWhenCollapsed;
11881191
}
11891192

1193+
private _columnPipeArgs: IColumnPipeArgs = { format: DEFAULT_DATE_FORMAT, digitsInfo: DEFAULT_DIGITS_INFO };
1194+
/**
1195+
* @remarks
1196+
* Pass optional parameters for DatePipe and/or DecimalPipe to format the display value for date and numeric columns.
1197+
* Accepts an `IColumnPipeArgs` object with any of the `format`, `timezone` and `digitsInfo` properties.
1198+
* For more details see https://angular.io/api/common/DatePipe and https://angular.io/api/common/DecimalPipe
1199+
* @example
1200+
* ```typescript
1201+
* const pipeArgs: IColumnPipeArgs = {
1202+
* format: 'longDate',
1203+
* timezone: 'UTC',
1204+
* digitsInfo: '1.1-2'
1205+
* }
1206+
* ```
1207+
* ```html
1208+
* <igx-column dataType="date" [pipeArgs]="pipeArgs"></igx-column>
1209+
* <igx-column dataType="number" [pipeArgs]="pipeArgs"></igx-column>
1210+
* ```
1211+
* @memberof IgxColumnComponent
1212+
*/
1213+
@Input()
1214+
set pipeArgs(value: IColumnPipeArgs) {
1215+
this._columnPipeArgs = Object.assign(this._columnPipeArgs, value);
1216+
this.grid.summaryService.clearSummaryCache();
1217+
(this.grid as any)._pipeTrigger++;
1218+
this.grid.notifyChanges();
1219+
}
1220+
get pipeArgs(): IColumnPipeArgs {
1221+
return this._columnPipeArgs;
1222+
}
1223+
11901224
/**
11911225
* @hidden
11921226
* @internal

projects/igniteui-angular/src/lib/grids/columns/interfaces.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { IgxColumnComponent } from './column.component';
22

33

4+
/**
5+
* @hidden
6+
* @internal
7+
*/
48
export interface MRLColumnSizeInfo {
59
ref: IgxColumnComponent;
610
width: number;
@@ -9,7 +13,26 @@ export interface MRLColumnSizeInfo {
913
widthSetByUser: boolean;
1014
}
1115

16+
/**
17+
* @hidden
18+
* @internal
19+
*/
1220
export interface MRLResizeColumnInfo {
1321
target: IgxColumnComponent;
1422
spanUsed: number;
1523
}
24+
25+
export interface IColumnPipeArgs {
26+
/** The date/time components that a date column will display, using predefined options or a custom format string. */
27+
format?: string;
28+
/** A timezone offset (such as '+0430'), or a standard UTC/GMT or continental US timezone abbreviation. */
29+
timezone?: string;
30+
/**
31+
* Decimal representation options, specified by a string in the following format:
32+
* `{minIntegerDigits}`.`{minFractionDigits}`-`{maxFractionDigits}`.
33+
* `minIntegerDigits`: The minimum number of integer digits before the decimal point. Default is 1.
34+
* `minFractionDigits`: The minimum number of digits after the decimal point. Default is 0.
35+
* `maxFractionDigits`: The maximum number of digits after the decimal point. Default is 3.
36+
*/
37+
digitsInfo?: string;
38+
}

projects/igniteui-angular/src/lib/grids/common/column.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TemplateRef } from '@angular/core';
22
import { DataType } from '../../data-operations/data-util';
33
import { ISortingStrategy } from '../../data-operations/sorting-strategy';
44
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
5+
import { IColumnPipeArgs } from '../columns/interfaces';
56

67
/**
78
* @hidden
@@ -44,5 +45,6 @@ export interface ColumnType {
4445
topLevelParent?: ColumnType;
4546
parent?: ColumnType;
4647
hasLastPinnedChildColumn: boolean;
48+
pipeArgs: IColumnPipeArgs;
4749
getGridTemplate(isRow: boolean, isIE: boolean): string;
4850
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
IgxGridCellStyleClassesPipe,
1010
IgxGridPaginatorOptionsPipe,
1111
IgxHasVisibleColumnsPipe,
12-
IgxDatePipeComponent,
13-
IgxDecimalPipeComponent,
1412
IgxGridRowPinningPipe,
1513
IgxColumnActionEnabledPipe,
1614
IgxFilterActionColumnsPipe,
@@ -24,8 +22,6 @@ import {
2422

2523
@NgModule({
2624
declarations: [
27-
IgxDatePipeComponent,
28-
IgxDecimalPipeComponent,
2925
IgxGridFilterConditionPipe,
3026
IgxGridTransactionPipe,
3127
IgxGridNotGroupedPipe,
@@ -45,8 +41,6 @@ import {
4541
IgxColumnFormatterPipe
4642
],
4743
exports: [
48-
IgxDatePipeComponent,
49-
IgxDecimalPipeComponent,
5044
IgxGridFilterConditionPipe,
5145
IgxGridTransactionPipe,
5246
IgxGridNotGroupedPipe,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { EventEmitter } from '@angular/core';
44
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
55
import { IGridResourceStrings } from '../../core/i18n/grid-resources';
66
import { ISortingExpression } from '../../data-operations/sorting-expression.interface';
7+
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
8+
import { TransactionService, Transaction, State } from '../../services/public_api';
9+
import { ITreeGridRecord } from '../tree-grid/public_api';
710

811
export interface IGridDataBindable {
912
data: any[];
@@ -46,6 +49,8 @@ export interface GridType extends IGridDataBindable {
4649
summariesRowList: any;
4750
headerContainer: any;
4851
dataView: any[];
52+
transactions: TransactionService<Transaction, State>;
53+
defaultSummaryHeight: number;
4954

5055
rowInEditMode: any;
5156
rowEditTabs: any;
@@ -56,6 +61,8 @@ export interface GridType extends IGridDataBindable {
5661

5762
sortingExpressions: ISortingExpression[];
5863
sortingExpressionsChange: EventEmitter<ISortingExpression[]>;
64+
filteringExpressionsTree: IFilteringExpressionsTree;
65+
filteringExpressionsTreeChange: EventEmitter<IFilteringExpressionsTree>;
5966
advancedFilteringExpressionsTree: IFilteringExpressionsTree;
6067
advancedFilteringExpressionsTreeChange: EventEmitter<IFilteringExpressionsTree>;
6168

@@ -66,6 +73,22 @@ export interface GridType extends IGridDataBindable {
6673
isColumnGrouped(fieldName: string): boolean;
6774
isDetailRecord(rec: any): boolean;
6875
isGroupByRecord(rec: any): boolean;
76+
notifyChanges(repaint: boolean): void;
77+
}
78+
79+
/**
80+
* An interface describing a Flat Grid type
81+
*/
82+
export interface FlatGridType extends GridType {
83+
groupingExpressions: IGroupingExpression[];
84+
groupingExpressionsChange: EventEmitter<IGroupingExpression[]>;
85+
}
86+
87+
/**
88+
* An interface describing a Tree Grid type
89+
*/
90+
export interface TreeGridType extends GridType {
91+
records: Map<any, ITreeGridRecord>;
6992
}
7093

7194
export interface GridSVGIcon {

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

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Pipe, PipeTransform, Inject, LOCALE_ID } from '@angular/core';
1+
import { Pipe, PipeTransform, Inject } from '@angular/core';
22
import { GridBaseAPIService } from '../api.service';
33
import { IgxGridBaseDirective } from '../grid-base.directive';
44
import { DataUtil } from '../../data-operations/data-util';
55
import { cloneArray, resolveNestedPath } from '../../core/utils';
66
import { GridType } from './grid.interface';
7-
import { DatePipe, DecimalPipe } from '@angular/common';
87
import { IgxColumnComponent } from '../columns/column.component';
98
import { ColumnDisplayOrder } from './enums';
109
import { IgxColumnActionsComponent } from '../column-actions/column-actions.component';
@@ -163,60 +162,6 @@ export class IgxHasVisibleColumnsPipe implements PipeTransform {
163162

164163
}
165164

166-
167-
/**
168-
* @hidden
169-
* @internal
170-
*/
171-
@Pipe({
172-
name: 'igxdate'
173-
})
174-
export class IgxDatePipeComponent extends DatePipe implements PipeTransform {
175-
176-
private readonly DEFAULT_DATE_FORMAT = 'mediumDate';
177-
178-
constructor(@Inject(LOCALE_ID) locale: string) {
179-
// D.P. constructor duplication due to es6 compilation, might be obsolete in the future
180-
super(locale);
181-
}
182-
transform(value: any, locale: string): string {
183-
if (value && value instanceof Date) {
184-
if (locale) {
185-
return super.transform(value, this.DEFAULT_DATE_FORMAT, undefined, locale);
186-
} else {
187-
return super.transform(value);
188-
}
189-
} else {
190-
return value;
191-
}
192-
}
193-
}
194-
195-
/**
196-
* @hidden
197-
* @internal
198-
*/
199-
@Pipe({
200-
name: 'igxdecimal'
201-
})
202-
export class IgxDecimalPipeComponent extends DecimalPipe implements PipeTransform {
203-
constructor(@Inject(LOCALE_ID) locale: string) {
204-
// D.P. constructor duplication due to es6 compilation, might be obsolete in the future
205-
super(locale);
206-
}
207-
transform(value: any, locale: string): string {
208-
if (value && typeof value === 'number') {
209-
if (locale) {
210-
return super.transform(value, undefined, locale);
211-
} else {
212-
return super.transform(value);
213-
}
214-
} else {
215-
return value;
216-
}
217-
}
218-
}
219-
220165
/**
221166
* @hidden
222167
*/

projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ <h6 class="igx-filter-empty__title">
108108
{{ getConditionFriendlyName(expressionItem.expression.condition.name) }}
109109
</span>
110110
<span igxSuffix *ngIf="!expressionItem.expression.condition.isUnary">
111-
{{ isDate(expressionItem.expression.searchVal) ? (expressionItem.expression.searchVal | igxdate:grid.locale) : expressionItem.expression.searchVal }}
111+
{{ isDate(expressionItem.expression.searchVal) ? (expressionItem.expression.searchVal | date:getFormat(expressionItem.expression.fieldName):getTimezone(expressionItem.expression.fieldName):grid.locale) : expressionItem.expression.searchVal }}
112112
</span>
113113
</igx-chip>
114114
<div class="igx-filter-tree__expression-actions"
@@ -191,7 +191,7 @@ <h6 class="igx-filter-empty__title">
191191
(click)="openDialog(dropDownTarget.element.nativeElement)"
192192
[placeholder]="grid.resourceStrings.igx_grid_filter_row_date_placeholder"
193193
autocomplete="off"
194-
[value]="value | igxdate: grid.locale"
194+
[value]="value | date:selectedColumn.pipeArgs.format:selectedColumn.pipeArgs.timezone:grid.locale"
195195
[readonly]="true"
196196
[disabled]="!selectedColumn || !selectedCondition || (selectedColumn && selectedColumn.filters.condition(selectedCondition).isUnary)"/>
197197
</igx-input-group>

projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,20 @@ export class IgxAdvancedFilteringDialogComponent implements AfterViewInit, OnDes
10381038
this._overlayComponentId = overlayComponentId;
10391039
}
10401040

1041+
/**
1042+
* @hidden @internal
1043+
*/
1044+
public getFormat(field: string) {
1045+
return this.grid.getColumnByName(field).pipeArgs.format;
1046+
}
1047+
1048+
/**
1049+
* @hidden @internal
1050+
*/
1051+
public getTimezone(field: string) {
1052+
return this.grid.getColumnByName(field).pipeArgs.timezone;
1053+
}
1054+
10411055
/**
10421056
* @hidden @internal
10431057
*/

0 commit comments

Comments
 (0)