• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 25808892300

13 May 2026 03:26PM UTC coverage: 90.167% (-0.007%) from 90.174%
25808892300

Pull #17246

github

web-flow
Merge 505fad556 into cd69e807d
Pull Request #17246: fix(pivot-grid): fix date format based on the localization

14861 of 17307 branches covered (85.87%)

Branch coverage included in aggregate %.

22 of 24 new or added lines in 3 files covered. (91.67%)

52 existing lines in 2 files now uncovered.

29904 of 32340 relevant lines covered (92.47%)

34546.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.96
/projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts
1
import { getCurrentResourceStrings, GridColumnDataType, GridResourceStringsEN, IGridResourceStrings } from 'igniteui-angular/core';
2
import { IPivotDimension } from './pivot-grid.interface';
3
import { PivotUtil } from './pivot-util';
4
import { getDateFormatter } from 'igniteui-i18n-core';
5

6
export interface IPivotDateDimensionOptions {
7
    /** Enables/Disables total value of all periods. */
8
    total?: boolean;
9
    /** Enables/Disables dimensions per year from provided periods. */
10
    years?: boolean;
11
    /*/** Enables/Disables dimensions per quarter from provided periods. */
12
    quarters?: boolean;
13
    /** Enables/Disables dimensions per month from provided periods. */
14
    months?: boolean;
15
    /** Enabled/Disables dimensions for the full date provided */
16
    fullDate?: boolean;
17
}
18

19
/* blazorAlternateBaseType: PivotDimension */
20
/* alternateBaseType: PivotDimension */
21
// Equals to pretty much this configuration:
22
// {
23
//     member: () => 'All Periods',
24
//     enabled: true,
25
//     fieldName: 'AllPeriods',
26
//     childLevel: {
27
//         fieldName: 'Years',
28
//         member: (rec) => {
29
//             const recordValue = rec['Date'];
30
//             return recordValue ? (new Date(recordValue)).getFullYear().toString() : rec['Years'];
31
//         },
32
//         enabled: true,
33
//         childLevel: {
34
//                 member: (rec) => {
35
//                     const recordValue = rec['Date'];
36
//                     return recordValue ? new Date(recordValue).toLocaleString('default', { month: 'long' }) : rec['Months'];
37
//                 },
38
//                 enabled: true,
39
//                 fieldName: 'Months',
40
//                 childLevel: {
41
//                         member: 'Date',
42
//                         fieldName:'Date',
43
//                         enabled: true
44
//                     }
45
//             }
46
//     }
47
// },
48
export class IgxPivotDateDimension implements IPivotDimension {
49
    /** Enables/Disables a particular dimension from pivot structure. */
50
    public enabled = true;
19✔
51

52
    /**
53
     * Gets/Sets data type
54
     */
55
    public dataType?: GridColumnDataType;
56

57
    /* blazorSuppress */
58
    /** Default options. */
59
    public defaultOptions = {
19✔
60
        total: true,
61
        years: true,
62
        months: true,
63
        fullDate: true
64
    };
65

66
    /**
67
     * Gets/Sets the resource strings.
68
     *
69
     * @remarks
70
     * By default it uses EN resources.
71
     */
72
    public set resourceStrings(value: IGridResourceStrings) {
73
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
74
    }
75

76
    public get resourceStrings(): IGridResourceStrings {
77
        return this._resourceStrings || getCurrentResourceStrings(GridResourceStringsEN, false);
394✔
78
    }
79

80
    /**
81
     * Gets/Sets the base dimension that is used by this class to determine the other dimensions and their values.
82
     * Having base dimension set is required in order for the Date Dimensions to show.
83
     */
84
    public get baseDimension(): IPivotDimension {
85
        return this._baseDimension;
40✔
86
    }
87
    public set baseDimension(value: IPivotDimension) {
88
        this._baseDimension = value;
1✔
89
        this.initialize(this.baseDimension, this.options);
1✔
90
    }
91

92
    /**
93
     * Gets/Sets the options for the predefined date dimensions whether to show quarter, years and etc.
94
     */
95
    public get options(): IPivotDateDimensionOptions {
96
        return this._options;
38✔
97
    }
98
    public set options(value: IPivotDateDimensionOptions) {
99
        this._options = value;
1✔
100
        if (this.baseDimension) {
1✔
101
            this.initialize(this.baseDimension, this.options);
1✔
102
        }
103
    }
104

105
    /** @hidden @internal */
106
    public childLevel?: IPivotDimension;
107
    /** @hidden @internal */
108
    public memberName = 'AllPeriods';
19✔
109
    public displayName: string;
110
    private _resourceStrings: IGridResourceStrings = null;
19✔
111
    private _baseDimension: IPivotDimension;
112
    private _options: IPivotDateDimensionOptions = {};
19✔
113

114
    /**
115
     * Creates additional pivot date dimensions based on a provided dimension describing date data:
116
     *
117
     * @param inDateDimension Base dimension that is used by this class to determine the other dimensions and their values.
118
     * @param inOptions Options for the predefined date dimensions whether to show quarter, years and etc.
119
     * @example
120
     * ```typescript
121
     * // Displays only years as parent dimension to the base dimension provided.
122
     * new IgxPivotDateDimension({ memberName: 'Date', enabled: true }, { total: false, months: false });
123
     * ```
124
     */
125
    constructor(inBaseDimension: IPivotDimension = null, inOptions: IPivotDateDimensionOptions = {}) {
3✔
126
        this._baseDimension = inBaseDimension;
19✔
127
        this._options = inOptions;
19✔
128
        if (this.baseDimension && this.options) {
19✔
129
            this.initialize(this.baseDimension, this.options);
18✔
130
        }
131
    }
132

133
    protected initialize(inBaseDimension, inOptions) {
134
        const options = { ...this.defaultOptions, ...inOptions };
20✔
135

136
        this.dataType = GridColumnDataType.Date;
20✔
137
        inBaseDimension.dataType = GridColumnDataType.Date;
20✔
138

139
        this.enabled = inBaseDimension.enabled;
20✔
140
        this.displayName = inBaseDimension.displayName || this.resourceStrings.igx_grid_pivot_date_dimension_total;
20✔
141

142
        // When fullDate is enabled, attach a locale-aware formatter unless the user has
143
        // already supplied their own headerFormatter on inBaseDimension.
144
        // The memberFunction (if any) is kept intact via the spread — the formatter is
145
        // a separate display-only concern and should not be gated on memberFunction.
146
        let baseDimension: IPivotDimension = null;
20✔
147
        if (options.fullDate) {
20✔
148
            if (inBaseDimension.headerFormatter) {
19!
149
                // User supplied their own formatter — use the dimension as-is.
NEW
150
                baseDimension = inBaseDimension;
×
151
            } else {
152
                const dateFormatter = getDateFormatter();
19✔
153
                // No user-supplied formatter: create a new dimension object with a locale-aware
154
                // formatter that shows dates in short-date format.
155
                baseDimension = {
19✔
156
                    ...inBaseDimension,
157
                    headerFormatter: (value: any) => {
158
                        const hasValue = value !== null && value !== undefined && value !== '';
61✔
159
                        const dateValue = hasValue ? dateFormatter.createDateFromValue(value) : null;
61!
160
                        if (dateValue) {
61✔
161
                            return dateFormatter.formatDateTime(dateValue, undefined, { dateStyle: 'short' });
61✔
162
                        }
NEW
163
                        return hasValue ? String(value) : '';
×
164
                    }
165
                };
166
            }
167
        }
168

169
        const monthDimensionDef: IPivotDimension = {
20✔
170
            memberName: 'Months',
171
            memberFunction: (rec) => {
172
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
93✔
173
                const dateValue = (recordValue != null && recordValue !== '') ? getDateFormatter().createDateFromValue(recordValue) : null;
93!
174
                return (recordValue != null && recordValue !== '') ? getDateFormatter().formatDateTime(dateValue, undefined, { month: 'long'}) : rec['Months'];
93!
175
            },
176
            enabled: true,
177
            childLevel: baseDimension
178
        };
179
        const monthDimension = options.months ? monthDimensionDef : baseDimension;
20✔
180

181
        const quarterDimensionDef: IPivotDimension = {
20✔
182
            memberName: 'Quarters',
183
            memberFunction: (rec) => {
184
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
48✔
185
                const dateValue = (recordValue != null && recordValue !== '') ? getDateFormatter().createDateFromValue(recordValue) : null;
48!
186
                return (recordValue != null && recordValue !== '') ? `Q` + Math.ceil((dateValue.getMonth() + 1) / 3) : rec['Quarters'];
48!
187
            },
188
            enabled: true,
189
            childLevel: monthDimension
190
        };
191
        const quarterDimension = options.quarters ? quarterDimensionDef : monthDimension;
20✔
192

193
        const yearsDimensionDef: IPivotDimension = {
20✔
194
            memberName: 'Years',
195
            memberFunction: (rec) => {
196
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
394✔
197
                const dateValue = (recordValue != null && recordValue !== '') ? getDateFormatter().createDateFromValue(recordValue) : null;
394!
198
                return (recordValue != null && recordValue !== '') ? dateValue.getFullYear().toString() : rec['Years'];
394!
199
            },
200
            enabled: true,
201
            childLevel: quarterDimension
202
        };
203
        const yearsDimension = options.years ? yearsDimensionDef : quarterDimension;
20✔
204
        this.childLevel = yearsDimension;
20✔
205

206
        if (!options.total) {
20✔
207
            this.memberName = yearsDimension.memberName;
3✔
208
            this.memberFunction = yearsDimension.memberFunction;
3✔
209
            this.childLevel = yearsDimension.childLevel;
3✔
210
            this.displayName = yearsDimension.displayName;
3✔
211
        }
212
    }
213

214
    /** @hidden @internal */
215
    public memberFunction = (_data) => this.resourceStrings.igx_grid_pivot_date_dimension_total;
373✔
216
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc