Skip to content

Commit 1ebf0ea

Browse files
Merge branch 'master' into ddimitrov/advancedFiltering
2 parents 3e80ed1 + 9831e6f commit 1ebf0ea

File tree

5 files changed

+92
-8
lines changed

5 files changed

+92
-8
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,8 @@ export class IgxColumnComponent implements AfterContentInit {
16871687
*/
16881688
public get pinnable() {
16891689
const gridUnpinnedWidth = (this.grid as any).getUnpinnedWidth(true);
1690-
const columnWidth = parseInt(this.width, 10);
1691-
return !((gridUnpinnedWidth - columnWidth) < this.grid.unpinnedAreaMinWidth);
1690+
const elementWidth = this.parent ? parseInt(this.topLevelParent.width, 10) : parseInt(this.width, 10);
1691+
return !((gridUnpinnedWidth - elementWidth) < this.grid.unpinnedAreaMinWidth);
16921692
}
16931693

16941694
/**

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

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit {
2929
@Input()
3030
public data: FilterListItem[];
3131

32+
public filteredData: FilterListItem[];
33+
3234
@Input()
3335
public column: IgxColumnComponent;
3436

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Pipe, PipeTransform } from '@angular/core';
2-
import { FilterListItem } from './grid.excel-style-filtering.component';
2+
import { FilterListItem, IgxGridExcelStyleFilteringComponent } from './grid.excel-style-filtering.component';
3+
import { cloneArray } from '../../../core/utils';
34

45
/**
56
* @hidden
@@ -8,12 +9,16 @@ import { FilterListItem } from './grid.excel-style-filtering.component';
89
name: 'excelStyleSearchFilter'
910
})
1011
export class IgxExcelStyleSearchFilterPipe implements PipeTransform {
12+
13+
constructor(private esf: IgxGridExcelStyleFilteringComponent) { }
14+
1115
transform(items: FilterListItem[], searchText: string): any[] {
1216
if (!items || !items.length) {
1317
return [];
1418
}
1519

1620
if (!searchText) {
21+
this.esf.excelStyleSearch.filteredData = null;
1722
return items;
1823
}
1924

@@ -22,6 +27,14 @@ export class IgxExcelStyleSearchFilterPipe implements PipeTransform {
2227
(it.value !== null && it.value !== undefined) &&
2328
it.value.toString().toLowerCase().indexOf(searchText) > -1);
2429

25-
return result.length > 1 ? result : [];
30+
// If 'result' contains the 'Select All' item and at least one more, we use it as a 'finalResult',
31+
// otherwise we use an empty array as a 'finalResult' of the filtering.
32+
const finalResult = result.length > 1 ? result : [];
33+
34+
// Update the filteredData of the search component.
35+
this.esf.excelStyleSearch.filteredData = cloneArray(finalResult);
36+
this.esf.cdr.detectChanges();
37+
38+
return finalResult;
2639
}
2740
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
132132
public customDialog: IgxExcelStyleCustomDialogComponent;
133133

134134
@ViewChild('excelStyleSearch', { read: IgxExcelStyleSearchComponent, static: true })
135-
protected excelStyleSearch: IgxExcelStyleSearchComponent;
135+
public excelStyleSearch: IgxExcelStyleSearchComponent;
136136

137137
@ViewChild('excelStyleSorting', { read: IgxExcelStyleSortingComponent, static: false })
138138
protected excelStyleSorting: IgxExcelStyleSortingComponent;
@@ -172,7 +172,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
172172
}
173173
}
174174

175-
constructor(private cdr: ChangeDetectorRef) {}
175+
constructor(public cdr: ChangeDetectorRef) {}
176176

177177
ngOnInit() {
178178
this.isColumnPinnable = this.column.pinnable;
@@ -552,7 +552,8 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
552552
}
553553

554554
get applyButtonDisabled() {
555-
return this.listData[0] && !this.listData[0].isSelected && !this.listData[0].indeterminate;
555+
return (this.excelStyleSearch.filteredData && this.excelStyleSearch.filteredData.length === 0) ||
556+
(this.listData[0] && !this.listData[0].isSelected && !this.listData[0].indeterminate);
556557
}
557558

558559
public applyFilter() {

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

+69-1
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,8 @@ describe('IgxGrid - Filtering actions - Excel style filtering', () => {
35043504
declarations: [
35053505
IgxGridFilteringComponent,
35063506
IgxTestExcelFilteringDatePickerComponent,
3507-
IgxGridFilteringESFTemplatesComponent
3507+
IgxGridFilteringESFTemplatesComponent,
3508+
IgxGridFilteringMCHComponent
35083509
],
35093510
imports: [
35103511
NoopAnimationsModule,
@@ -4258,6 +4259,42 @@ describe('IgxGrid - Filtering actions - Excel style filtering', () => {
42584259
tick(100);
42594260
}));
42604261

4262+
it('Should filter, clear and enable/disable the apply button correctly.', fakeAsync(() => {
4263+
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
4264+
tick(100);
4265+
fix.detectChanges();
4266+
4267+
// Type string in search box.
4268+
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4269+
const inputNativeElement = searchComponent.querySelector('.igx-input-group__input');
4270+
sendInputNativeElement(inputNativeElement, 'hello there', fix);
4271+
tick(100);
4272+
fix.detectChanges();
4273+
4274+
// Verify there are no filtered-in results and that apply button is disabled.
4275+
let listItems = searchComponent.querySelectorAll('igx-list-item');
4276+
let excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
4277+
let raisedButtons = Array.from(excelMenu.querySelectorAll('.igx-button--raised'));
4278+
let applyButton: any = raisedButtons.find((rb: any) => rb.innerText === 'apply');
4279+
expect(listItems.length).toBe(0, 'ESF search result should be empty');
4280+
expect(applyButton.classList.contains('igx-button--disabled')).toBe(true);
4281+
4282+
// Clear filtering.
4283+
const icons = Array.from(searchComponent.querySelectorAll('igx-icon'));
4284+
const clearIcon: any = icons.find((ic: any) => ic.innerText === 'clear');
4285+
clearIcon.click();
4286+
tick(100);
4287+
fix.detectChanges();
4288+
4289+
// Verify there are filtered-in results and that apply button is enabled.
4290+
listItems = searchComponent.querySelectorAll('igx-list-item');
4291+
excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
4292+
raisedButtons = Array.from(excelMenu.querySelectorAll('.igx-button--raised'));
4293+
applyButton = raisedButtons.find((rb: any) => rb.innerText === 'apply');
4294+
expect(listItems.length).toBe(6, 'ESF search result should NOT be empty');
4295+
expect(applyButton.classList.contains('igx-button--disabled')).toBe(false);
4296+
}));
4297+
42614298
it('display density is properly applied on the excel style filtering component', fakeAsync(() => {
42624299
const gridNativeElement = fix.debugElement.query(By.css('igx-grid')).nativeElement;
42634300
const column = grid.columns.find((c) => c.field === 'ProductName');
@@ -5578,6 +5615,37 @@ describe('IgxGrid - Filtering actions - Excel style filtering', () => {
55785615
// expect(datePicker.componentInstance.templateDropDownTarget).toBeTruthy();
55795616
}));
55805617
});
5618+
5619+
describe(null, () => {
5620+
let fix, grid;
5621+
beforeEach(fakeAsync(() => {
5622+
fix = TestBed.createComponent(IgxGridFilteringMCHComponent);
5623+
grid = fix.componentInstance.grid;
5624+
grid.filterMode = FilterMode.excelStyleFilter;
5625+
fix.detectChanges();
5626+
}));
5627+
5628+
it('Should not pin column when its parent group cannot be pinned.', fakeAsync(() => {
5629+
// Test prerequisites
5630+
grid.width = '1000px';
5631+
fix.detectChanges();
5632+
tick(100);
5633+
5634+
// Pin the 'AnotherField' column.
5635+
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
5636+
fix.detectChanges();
5637+
GridFunctions.clickPinIconInExcelStyleFiltering(fix, false);
5638+
tick(200);
5639+
fix.detectChanges();
5640+
5641+
// Verify that the 'ProductName' pin button is disabled, because its parent column cannot be pinned.
5642+
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
5643+
fix.detectChanges();
5644+
const pinButton = GridFunctions.getExcelFilteringPinContainer(fix);
5645+
expect(pinButton.classList.contains('igx-excel-filter__actions-pin--disabled')).toBe(true,
5646+
'pinButton should be disabled');
5647+
}));
5648+
});
55815649
});
55825650

55835651
const expectedResults = [];

0 commit comments

Comments
 (0)