Skip to content

Commit 4afad0e

Browse files
authored
Merge branch '13.0.x' into izhostov/fix-tab-scroll-13.0.x
2 parents a9bce52 + 5362121 commit 4afad0e

File tree

3 files changed

+94
-13
lines changed

3 files changed

+94
-13
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { GridType } from './grid.interface';
1111
const DATE_TYPE = 'date';
1212
const TIME_TYPE = 'time';
1313
const DATE_TIME_TYPE = 'dateTime';
14+
const STRING_TYPE = 'string';
1415

1516
export interface IGridSortingStrategy {
1617
sort(data: any[], expressions: ISortingExpression[], grid?: GridType): any[];
@@ -43,7 +44,8 @@ export class IgxSorting implements IGridSortingStrategy {
4344
const column = grid ? grid.getColumnByName(expressions[level].fieldName) : null;
4445
const isDate = column?.dataType === DATE_TYPE || column?.dataType === DATE_TIME_TYPE;
4546
const isTime = column?.dataType === TIME_TYPE;
46-
const group = this.groupedRecordsByExpression(data, i, expressions[level], isDate);
47+
const isString = column?.dataType === STRING_TYPE;
48+
const group = this.groupedRecordsByExpression(data, i, expressions[level], isDate, isString);
4749
const groupRow: IGroupByRecord = {
4850
expression: expressions[level],
4951
level,
@@ -104,17 +106,24 @@ export class IgxSorting implements IGridSortingStrategy {
104106
data: T[],
105107
index: number,
106108
expression: IGroupingExpression,
107-
isDate: boolean = false
109+
isDate: boolean = false,
110+
isString: boolean
108111
): T[] {
109112
const res = [];
110113
const key = expression.fieldName;
111114
const len = data.length;
112-
const groupval = this.getFieldValue(data[index], key, isDate);
115+
let groupval = this.getFieldValue(data[index], key, isDate);
113116
res.push(data[index]);
114117
index++;
115118
const comparer = expression.groupingComparer || DefaultSortingStrategy.instance().compareValues;
116119
for (let i = index; i < len; i++) {
117-
if (comparer(this.getFieldValue(data[i], key, isDate), groupval) === 0) {
120+
let fieldValue = this.getFieldValue(data[i], key, isDate);
121+
if (expression.ignoreCase && isString) {
122+
// when column's dataType is string but the value is number
123+
fieldValue = fieldValue?.toString().toLowerCase();
124+
groupval = groupval?.toString().toLowerCase();
125+
}
126+
if (comparer(fieldValue, groupval) === 0) {
118127
res.push(data[i]);
119128
} else {
120129
break;
@@ -147,13 +156,14 @@ export class IgxSorting implements IGridSortingStrategy {
147156
const column = grid?.getColumnByName(expr.fieldName);
148157
const isDate = column?.dataType === DATE_TYPE || column?.dataType === DATE_TIME_TYPE;
149158
const isTime = column?.dataType === TIME_TYPE;
159+
const isString = column?.dataType === STRING_TYPE;
150160
data = expr.strategy.sort(data, expr.fieldName, expr.dir, expr.ignoreCase, this.getFieldValue, isDate, isTime);
151161
if (expressionIndex === exprsLen - 1) {
152162
return data;
153163
}
154164
// in case of multiple sorting
155165
for (i = 0; i < dataLen; i++) {
156-
gbData = this.groupedRecordsByExpression(data, i, expr, isDate);
166+
gbData = this.groupedRecordsByExpression(data, i, expr, isDate, isString);
157167
gbDataLen = gbData.length;
158168
if (gbDataLen > 1) {
159169
gbData = this.sortDataRecursive(gbData, expressions, expressionIndex + 1, grid);

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

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('IgxGrid - GroupBy #grid', () => {
3939
GroupByDataMoreColumnsComponent,
4040
GroupByEmptyColumnFieldComponent,
4141
MultiColumnHeadersWithGroupingComponent,
42-
GridGroupByRowCustomSelectorsComponent
42+
GridGroupByRowCustomSelectorsComponent,
43+
GridGroupByCaseSensitiveComponent
4344
],
4445
imports: [NoopAnimationsModule, IgxGridModule]
4546
});
@@ -63,7 +64,11 @@ describe('IgxGrid - GroupBy #grid', () => {
6364
if (level === maxLevel) {
6465
count++;
6566
}
66-
expect(rec[field]).toEqual(val);
67+
if (groupRow.groupRow.expression.ignoreCase) {
68+
expect(rec[field]?.toString().toLowerCase()).toEqual(val?.toString().toLowerCase());
69+
} else {
70+
expect(rec[field]).toEqual(val);
71+
}
6772
}
6873
}
6974
};
@@ -376,6 +381,30 @@ describe('IgxGrid - GroupBy #grid', () => {
376381
grid.groupingExpressions);
377382
}));
378383

384+
it('should group records correctly when ignoreCase is set to true.', fakeAsync(() => {
385+
const fix = TestBed.createComponent(GridGroupByCaseSensitiveComponent);
386+
fix.detectChanges();
387+
388+
// set groupingExpressions
389+
const grid = fix.componentInstance.instance;
390+
const exprs: ISortingExpression[] = [
391+
{ fieldName: 'ContactTitle', dir: SortingDirection.Asc, ignoreCase: true }
392+
];
393+
grid.groupingExpressions = exprs;
394+
tick();
395+
fix.detectChanges();
396+
397+
let groupRows = grid.groupsRowList.toArray();
398+
let dataRows = grid.dataRowList.toArray();
399+
400+
expect(groupRows.length).toEqual(2);
401+
expect(dataRows.length).toEqual(5);
402+
// verify groups
403+
checkGroups(groupRows,
404+
['Order Administrator', 'Owner'],
405+
grid.groupingExpressions);
406+
}));
407+
379408
it('should allow setting expand/collapse state', fakeAsync(() => {
380409
const fix = TestBed.createComponent(DefaultGridComponent);
381410
const grid = fix.componentInstance.instance;
@@ -3701,3 +3730,45 @@ export class GridGroupByRowCustomSelectorsComponent extends DataParent {
37013730
this.groupByRowClick = _event;
37023731
}
37033732
}
3733+
3734+
@Component({
3735+
template: `
3736+
<igx-grid
3737+
[width]='width'
3738+
[height]='height'
3739+
[data]="testData">
3740+
<igx-column [field]="'ID'" [header]="'ID'" [width]="200" [groupable]="true" [hasSummary]="false"></igx-column>
3741+
<igx-column [field]="'ContactTitle'" [header]="'ContactTitle'" [width]="200" [groupable]="true" [hasSummary]="false"
3742+
dataType="string"></igx-column>
3743+
</igx-grid>
3744+
`
3745+
})
3746+
export class GridGroupByCaseSensitiveComponent extends DataParent {
3747+
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
3748+
public instance: IgxGridComponent;
3749+
3750+
public width = '800px';
3751+
public height = null;
3752+
public testData = [
3753+
{
3754+
ID: 1,
3755+
ContactTitle: "Owner"
3756+
},
3757+
{
3758+
ID: 2,
3759+
ContactTitle: 'Order Administrator'
3760+
},
3761+
{
3762+
ID: 3,
3763+
ContactTitle: "owner"
3764+
},
3765+
{
3766+
ID: 4,
3767+
ContactTitle: "Owner"
3768+
},
3769+
{
3770+
ID: 5,
3771+
ContactTitle: 'Order Administrator'
3772+
}
3773+
];
3774+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ describe('IgxGrid - Grid Sorting #grid', () => {
284284
grid.sortingExpressions = exprs;
285285

286286
fixture.detectChanges();
287-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('ALex');
288-
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Smith');
289-
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(5);
287+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('Alex');
288+
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Wilson');
289+
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(4);
290290
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('Rick');
291291
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('BRown');
292292
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(7);
@@ -299,9 +299,9 @@ describe('IgxGrid - Grid Sorting #grid', () => {
299299
grid.sort(exprs);
300300
fixture.detectChanges();
301301

302-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('ALex');
303-
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Smith');
304-
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(5);
302+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('Alex');
303+
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Wilson');
304+
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(4);
305305
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('Rick');
306306
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('BRown');
307307
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(7);

0 commit comments

Comments
 (0)