Skip to content

Commit 07a6f49

Browse files
committed
fix(esf): using column sort strategy for esf search
1 parent be244a8 commit 07a6f49

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ 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';
32+
import { IgxSorting } from '../../../data-operations/sorting-strategy';
3133

3234
/**
3335
* @hidden
@@ -557,7 +559,14 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
557559
this.addItems(shouldUpdateSelection);
558560
}
559561

560-
this.listData.sort((a, b) => this.sortData(a, b));
562+
const sorting = new IgxSorting();
563+
const expressions = [{
564+
dir: SortingDirection.Asc,
565+
fieldName: 'value',
566+
ignoreCase: this.column.filteringIgnoreCase,
567+
strategy: this.column.sortStrategy
568+
}];
569+
this.listData = sorting.sort(this.listData, expressions);
561570

562571
if (this.containsNullOrEmpty) {
563572
this.addBlanksItem(shouldUpdateSelection);
@@ -700,23 +709,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
700709
this.listData.unshift(blanks);
701710
}
702711

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-
719-
private getFilterItemLabel(element: any) {
712+
private getFilterItemLabel(element: any, applyFormatter: boolean = true) {
720713
if (this.column.dataType === DataType.Date) {
721714
return element && element.label ? element.label : this.column.formatter ?
722715
this.column.formatter(element) :

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
@@ -3990,8 +3990,8 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
39903990
fix.detectChanges();
39913991

39923992
verifyExcelStyleFilterAvailableOptions(fix,
3993-
['Select All', '(Blanks)', '0', '20', '100', '127', '254'],
3994-
[true, true, true, true, true, true, true]);
3993+
['Select All', '(Blanks)', '0', '20', '100', '127', '254', '702', '1,000'],
3994+
[true, true, true, true, true, true, true, true, true]);
39953995

39963996
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
39973997
tick(100);
@@ -4780,33 +4780,27 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
47804780
const column = grid.getColumnByName('AnotherField');
47814781
expect(column.filteringIgnoreCase).toBeTrue();
47824782

4783-
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'AnotherField');
4783+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
47844784
tick(100);
47854785
fix.detectChanges();
47864786

4787-
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4788-
const listItems = GridFunctions.getExcelStyleSearchComponentListItems(fix, searchComponent);
4789-
4790-
expect(listItems.length).toBe(3, 'incorrect rendered list items count');
4791-
expect(listItems[1].innerText).toBe('Custom', 'incorrect list item label');
4787+
verifyExcelStyleFilterAvailableOptions(fix,
4788+
['Select All', 'a', 'Custom'],
4789+
[true, true, true]);
47924790
}));
47934791

47944792
it('Should not ignore duplicate records when column\'\s filteringIgnoreCase is false', fakeAsync(() => {
47954793
const column = grid.getColumnByName('AnotherField');
47964794
column.filteringIgnoreCase = false;
47974795
expect(column.filteringIgnoreCase).toBeFalse();
47984796

4799-
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'AnotherField');
4797+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
48004798
tick(100);
48014799
fix.detectChanges();
48024800

4803-
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4804-
const listItems = GridFunctions.getExcelStyleSearchComponentListItems(fix, searchComponent);
4805-
4806-
expect(listItems.length).toBe(5, 'incorrect rendered list items count');
4807-
expect(listItems[1].innerText).toBe('Custom', 'incorrect list item label');
4808-
expect(listItems[3].innerText).toBe('custoM', 'incorrect list item label');
4809-
expect(listItems[4].innerText).toBe('custom', 'incorrect list item label');
4801+
verifyExcelStyleFilterAvailableOptions(fix,
4802+
['Select All', 'Custom', 'a', 'custoM', 'custom'],
4803+
[true, true, true, true, true]);
48104804
}));
48114805

48124806
it('Should display "Add to current filter selection" button on typing in input', fakeAsync(() => {
@@ -5135,6 +5129,47 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
51355129
expect(listItems[2].innerText).toBe('No', 'incorrect list item label');
51365130
expect(listItems[3].innerText).toBe('Yes', 'incorrect list item label');
51375131
}));
5132+
5133+
it('Should sort items in excel style search case INsensitive', fakeAsync(() => {
5134+
const data = [
5135+
{
5136+
Downloads: 254,
5137+
ID: 1,
5138+
ProductName: 'Ignite UI for JavaScript',
5139+
ReleaseDate: null,
5140+
Released: false,
5141+
AnotherField: 'BWord'
5142+
},
5143+
{
5144+
Downloads: 127,
5145+
ID: 2,
5146+
ProductName: 'NetAdvantage',
5147+
ReleaseDate: null,
5148+
Released: true,
5149+
AnotherField: 'bWord'
5150+
},
5151+
{
5152+
Downloads: 20,
5153+
ID: 3,
5154+
ProductName: 'Ignite UI for Angular',
5155+
ReleaseDate: null,
5156+
Released: null,
5157+
AnotherField: 'aWord'
5158+
}
5159+
];
5160+
fix.componentInstance.data = data;
5161+
fix.detectChanges();
5162+
5163+
// Open excel style custom filtering dialog.
5164+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
5165+
tick(100);
5166+
fix.detectChanges();
5167+
5168+
// Verify items order
5169+
verifyExcelStyleFilterAvailableOptions(fix,
5170+
['Select All', 'aWord', 'BWord'],
5171+
[true, true, true]);
5172+
}));
51385173
});
51395174

51405175
describe('Templates: ', () => {
@@ -5600,7 +5635,6 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
56005635

56015636
tick(1050);
56025637
fix.detectChanges();
5603-
56045638
}));
56055639

56065640
it('Done callback should be executed only once per column', fakeAsync(() => {
@@ -6179,6 +6213,7 @@ function verifyExcelStyleFilterAvailableOptions(fix, labels: string[], checked:
61796213
const labelElements: any[] = Array.from(GridFunctions.getExcelStyleSearchComponentListItems(fix, excelMenu));
61806214
const checkboxElements: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu));
61816215

6216+
expect(labelElements.length).toBe(labels.length, 'incorrect rendered list items count');
61826217
expect(labelElements.length).toBeGreaterThan(2);
61836218
expect(checkboxElements.length).toBeGreaterThan(2);
61846219
labels.forEach((l, index) => {

0 commit comments

Comments
 (0)