Skip to content

Commit c6344fd

Browse files
authored
Merge pull request #9357 from IgniteUI/dmdimitrov/fix-9307-10.2.x
fix(esf): using column sort strategy for esf search - 10.2.x
2 parents c008fd5 + 0b59fc4 commit c6344fd

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

projects/igniteui-angular/src/lib/grids/filtering/excel-style/grid.excel-style-filtering.component.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { IgxGridBaseDirective } from '../../grid-base.directive';
2828
import { DisplayDensity } from '../../../core/density';
2929
import { GridSelectionMode } from '../../common/enums';
3030
import { GridBaseAPIService } from '../../api.service';
31+
import { SortingDirection } from '../../../data-operations/sorting-expression.interface';
3132

3233
/**
3334
* @hidden
@@ -557,7 +558,8 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
557558
this.addItems(shouldUpdateSelection);
558559
}
559560

560-
this.listData.sort((a, b) => this.sortData(a, b));
561+
this.listData = this.column.sortStrategy.sort(this.listData, 'value', SortingDirection.Asc, this.column.sortingIgnoreCase,
562+
(obj, key) => obj[key]);
561563

562564
if (this.containsNullOrEmpty) {
563565
this.addBlanksItem(shouldUpdateSelection);
@@ -700,22 +702,6 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
700702
this.listData.unshift(blanks);
701703
}
702704

703-
private sortData(a: FilterListItem, b: FilterListItem) {
704-
let valueA = a.value;
705-
let valueB = b.value;
706-
if (typeof(a) === DataType.String) {
707-
valueA = a.value.toUpperCase();
708-
valueB = b.value.toUpperCase();
709-
}
710-
if (valueA < valueB) {
711-
return -1;
712-
} else if (valueA > valueB) {
713-
return 1;
714-
} else {
715-
return 0;
716-
}
717-
}
718-
719705
private getFilterItemLabel(element: any) {
720706
if (this.column.dataType === DataType.Date) {
721707
return element && element.label ? element.label : this.column.formatter ?

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

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,8 +4013,8 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
40134013
fix.detectChanges();
40144014

40154015
verifyExcelStyleFilterAvailableOptions(fix,
4016-
['Select All', '(Blanks)', '0', '20', '100', '127', '254'],
4017-
[true, true, true, true, true, true, true]);
4016+
['Select All', '(Blanks)', '0', '20', '100', '127', '254', '702', '1,000'],
4017+
[true, true, true, true, true, true, true, true, true]);
40184018

40194019
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
40204020
tick(100);
@@ -4803,33 +4803,27 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
48034803
const column = grid.getColumnByName('AnotherField');
48044804
expect(column.filteringIgnoreCase).toBeTrue();
48054805

4806-
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'AnotherField');
4806+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
48074807
tick(100);
48084808
fix.detectChanges();
48094809

4810-
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4811-
const listItems = GridFunctions.getExcelStyleSearchComponentListItems(fix, searchComponent);
4812-
4813-
expect(listItems.length).toBe(3, 'incorrect rendered list items count');
4814-
expect(listItems[1].innerText).toBe('Custom', 'incorrect list item label');
4810+
verifyExcelStyleFilterAvailableOptions(fix,
4811+
['Select All', 'a', 'Custom'],
4812+
[true, true, true]);
48154813
}));
48164814

48174815
it('Should not ignore duplicate records when column\'\s filteringIgnoreCase is false', fakeAsync(() => {
48184816
const column = grid.getColumnByName('AnotherField');
48194817
column.filteringIgnoreCase = false;
48204818
expect(column.filteringIgnoreCase).toBeFalse();
48214819

4822-
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'AnotherField');
4820+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
48234821
tick(100);
48244822
fix.detectChanges();
48254823

4826-
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4827-
const listItems = GridFunctions.getExcelStyleSearchComponentListItems(fix, searchComponent);
4828-
4829-
expect(listItems.length).toBe(5, 'incorrect rendered list items count');
4830-
expect(listItems[1].innerText).toBe('Custom', 'incorrect list item label');
4831-
expect(listItems[3].innerText).toBe('custoM', 'incorrect list item label');
4832-
expect(listItems[4].innerText).toBe('custom', 'incorrect list item label');
4824+
verifyExcelStyleFilterAvailableOptions(fix,
4825+
['Select All', 'a', 'Custom', 'custoM', 'custom'],
4826+
[true, true, true, true, true]);
48334827
}));
48344828

48354829
it('Should display "Add to current filter selection" button on typing in input', fakeAsync(() => {
@@ -5158,6 +5152,47 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
51585152
expect(listItems[2].innerText).toBe('No', 'incorrect list item label');
51595153
expect(listItems[3].innerText).toBe('Yes', 'incorrect list item label');
51605154
}));
5155+
5156+
it('Should sort items in excel style search correctly', fakeAsync(() => {
5157+
const data = [
5158+
{
5159+
Downloads: 254,
5160+
ID: 1,
5161+
ProductName: 'Ignite UI for JavaScript',
5162+
ReleaseDate: null,
5163+
Released: false,
5164+
AnotherField: 'BWord'
5165+
},
5166+
{
5167+
Downloads: 127,
5168+
ID: 2,
5169+
ProductName: 'NetAdvantage',
5170+
ReleaseDate: null,
5171+
Released: true,
5172+
AnotherField: 'bWord'
5173+
},
5174+
{
5175+
Downloads: 20,
5176+
ID: 3,
5177+
ProductName: 'Ignite UI for Angular',
5178+
ReleaseDate: null,
5179+
Released: null,
5180+
AnotherField: 'aWord'
5181+
}
5182+
];
5183+
fix.componentInstance.data = data;
5184+
fix.detectChanges();
5185+
5186+
// Open excel style custom filtering dialog for string column
5187+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
5188+
tick(100);
5189+
fix.detectChanges();
5190+
5191+
// Verify items order is case INsensitive
5192+
verifyExcelStyleFilterAvailableOptions(fix,
5193+
['Select All', 'aWord', 'BWord'],
5194+
[true, true, true]);
5195+
}));
51615196
});
51625197

51635198
describe('Templates: ', () => {
@@ -5623,7 +5658,6 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
56235658

56245659
tick(1050);
56255660
fix.detectChanges();
5626-
56275661
}));
56285662

56295663
it('Done callback should be executed only once per column', fakeAsync(() => {
@@ -6202,6 +6236,7 @@ function verifyExcelStyleFilterAvailableOptions(fix, labels: string[], checked:
62026236
const labelElements: any[] = Array.from(GridFunctions.getExcelStyleSearchComponentListItems(fix, excelMenu));
62036237
const checkboxElements: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu));
62046238

6239+
expect(labelElements.length).toBe(labels.length, 'incorrect rendered list items count');
62056240
expect(labelElements.length).toBeGreaterThan(2);
62066241
expect(checkboxElements.length).toBeGreaterThan(2);
62076242
labels.forEach((l, index) => {

0 commit comments

Comments
 (0)