Skip to content

Commit 522426d

Browse files
authored
Merge pull request #6051 from IgniteUI/mkirova/fix-2531
fix(igxGrid): Remove pinning limitations when pinned columns don't fi…
2 parents ce06888 + 9ff2b9d commit 522426d

13 files changed

+24
-539
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes for each version of this project will be documented in this
1313
- `IgxRowComponent` -> `IgxRowDirective`
1414
- `IgxHierarchicalGridBaseComponent` -> `IgxHierarchicalGridBaseDirective`
1515

16+
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
17+
- **Behavioral Change** - Pinning columns is no longer automatically prevented when the pinning area would exceed the size of the grid.
18+
1619
## 8.2.4
1720

1821
### RTL Support

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1689,9 +1689,7 @@ export class IgxColumnComponent implements AfterContentInit {
16891689
*@hidden
16901690
*/
16911691
public get pinnable() {
1692-
const gridUnpinnedWidth = (this.grid as any).getUnpinnedWidth(true);
1693-
const elementWidth = this.parent ? parseInt(this.topLevelParent.width, 10) : parseInt(this.width, 10);
1694-
return (this.grid as any)._init || !((gridUnpinnedWidth - elementWidth) < this.grid.unpinnedAreaMinWidth);
1692+
return (this.grid as any)._init || !this.pinned;
16951693
}
16961694

16971695
/**

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

+2-43
Original file line numberDiff line numberDiff line change
@@ -3238,30 +3238,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
32383238
return DisplayDensity.compact;
32393239
}
32403240

3241-
/**
3242-
* Returns the maximum width of the container for the pinned `IgxColumnComponent`s.
3243-
* The width is 80% of the total grid width.
3244-
* ```typescript
3245-
* const maxPinnedColWidth = this.grid.calcPinnedContainerMaxWidth;
3246-
* ```
3247-
* @memberof IgxGridBaseDirective
3248-
*/
3249-
get calcPinnedContainerMaxWidth(): number {
3250-
return (this.calcWidth * 80) / 100;
3251-
}
3252-
3253-
/**
3254-
* Returns the minimum width of the container for the unpinned `IgxColumnComponent`s.
3255-
* The width is 20% of the total grid width.
3256-
* ```typescript
3257-
* const minUnpinnedColWidth = this.grid.unpinnedAreaMinWidth;
3258-
* ```
3259-
* @memberof IgxGridBaseDirective
3260-
*/
3261-
get unpinnedAreaMinWidth(): number {
3262-
return (this.calcWidth * 20) / 100;
3263-
}
3264-
32653241
/**
32663242
* Returns the current width of the container for the pinned `IgxColumnComponent`s.
32673243
* ```typescript
@@ -5476,7 +5452,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
54765452
let currentPinnedWidth = 0;
54775453
const pinnedColumns = [];
54785454
const unpinnedColumns = [];
5479-
const newUnpinnedCols = [];
54805455

54815456
this.calculateGridWidth();
54825457
this.resetCaches();
@@ -5497,16 +5472,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
54975472
if (this._columns[i].pinned && !this._columns[i].parent) {
54985473
// Pinned column. Check if with it the unpinned min width is exceeded.
54995474
const colWidth = parseInt(this._columns[i].width, 10);
5500-
if (currentPinnedWidth + colWidth > this.calcWidth - this.unpinnedAreaMinWidth) {
5501-
// unpinned min width is exceeded. Unpin the columns and add it to the unpinned collection.
5502-
this._columns[i].pinned = false;
5503-
unpinnedColumns.push(this._columns[i]);
5504-
newUnpinnedCols.push(this._columns[i]);
5505-
} else {
5506-
// unpinned min width is not exceeded. Keep it pinned and add it to the pinned collection.
5507-
currentPinnedWidth += colWidth;
5508-
pinnedColumns.push(this._columns[i]);
5509-
}
5475+
currentPinnedWidth += colWidth;
5476+
pinnedColumns.push(this._columns[i]);
55105477
} else if (this._columns[i].pinned && this._columns[i].parent) {
55115478
if (this._columns[i].topLevelParent.pinned) {
55125479
pinnedColumns.push(this._columns[i]);
@@ -5519,14 +5486,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
55195486
}
55205487
}
55215488

5522-
if (newUnpinnedCols.length) {
5523-
console.warn(
5524-
'igxGrid - The pinned area exceeds maximum pinned width. ' +
5525-
'The following columns were unpinned to prevent further issues:' +
5526-
newUnpinnedCols.map(col => '"' + col.header + '"').toString() + '. For more info see our documentation.'
5527-
);
5528-
}
5529-
55305489
// Assign the applicaple collections.
55315490
this._pinnedColumns = pinnedColumns;
55325491
this._unpinnedColumns = unpinnedColumns;

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

-45
Original file line numberDiff line numberDiff line change
@@ -744,51 +744,6 @@ describe('IgxGrid - multi-column headers #grid', () => {
744744
});
745745
}));
746746

747-
it('column pinning - Try to pin column or group which exceeds the pinned area width.', fakeAsync(() => {
748-
const fixture = TestBed.createComponent(ColumnGroupFourLevelTestComponent);
749-
fixture.detectChanges();
750-
const ci = fixture.componentInstance;
751-
const grid = ci.grid;
752-
expect(grid.pinnedColumns.length).toEqual(0);
753-
expect(grid.unpinnedColumns.length).toEqual(18);
754-
755-
// Try to pin top group
756-
ci.addrInfoColGroup.pinned = true;
757-
fixture.detectChanges();
758-
tick();
759-
760-
// Verify group and all its children are not pinned
761-
testColumnPinning(ci.addrInfoColGroup, false);
762-
testColumnsOrder(ci.colsAndGroupsNaturalOrder);
763-
764-
expect(grid.pinnedColumns.length).toEqual(0);
765-
expect(grid.unpinnedColumns.length).toEqual(18);
766-
767-
// Try to pin a column
768-
ci.faxCol.pinned = true;
769-
fixture.detectChanges();
770-
tick();
771-
772-
// Verify group and all its children are not pinned
773-
testColumnPinning(ci.addrInfoColGroup, false);
774-
testColumnsOrder(ci.colsAndGroupsNaturalOrder);
775-
776-
expect(grid.pinnedColumns.length).toEqual(0);
777-
expect(grid.unpinnedColumns.length).toEqual(18);
778-
779-
// Try to pin child group
780-
ci.contactInfoColGroup.pinned = true;
781-
fixture.detectChanges();
782-
tick();
783-
784-
// Verify group and all its children are not pinned
785-
testColumnPinning(ci.addrInfoColGroup, false);
786-
testColumnsOrder(ci.colsAndGroupsNaturalOrder);
787-
788-
expect(grid.pinnedColumns.length).toEqual(0);
789-
expect(grid.unpinnedColumns.length).toEqual(18);
790-
}));
791-
792747
it('column pinning - Verify pin a not fully visble group', fakeAsync(() => {
793748
const fixture = TestBed.createComponent(ColumnGroupTwoGroupsTestComponent);
794749
fixture.detectChanges();

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

+4-28
Original file line numberDiff line numberDiff line change
@@ -225,42 +225,18 @@ describe('Column Pinning UI #grid', () => {
225225
expect(currentArgs.isPinned).toBe(false);
226226
}));
227227

228-
it('doesn\'t pin columns if unpinned area width will become less than the defined minimum.', async(() => {
228+
it('does pin columns if unpinned area width will become less than the defined minimum.', async(() => {
229229
const checkboxes = GridFunctions.getCheckboxInputs(columnChooserElement);
230230
checkboxes[0].click();
231231
checkboxes[1].click();
232232
checkboxes[2].click();
233233

234-
verifyColumnIsPinned(grid.columns[0], true, 2);
235-
verifyColumnIsPinned(grid.columns[1], true, 2);
236-
verifyColumnIsPinned(grid.columns[2], false, 2);
234+
verifyColumnIsPinned(grid.columns[0], true, 3);
235+
verifyColumnIsPinned(grid.columns[1], true, 3);
236+
verifyColumnIsPinned(grid.columns[2], true, 3);
237237

238238
}));
239239

240-
it('doesn\'t pin columns if unpinned area width does not allow it even after hiding a pinned column.', async(() => {
241-
let checkboxes = GridFunctions.getCheckboxInputs(columnChooserElement);
242-
checkboxes[0].click();
243-
checkboxes[1].click();
244-
245-
grid.columns[1].hidden = true;
246-
fix.detectChanges();
247-
248-
expect(grid.pinnedColumns.length).toBe(1);
249-
250-
checkboxes = GridFunctions.getCheckboxInputs(columnChooserElement);
251-
checkboxes[2].click();
252-
verifyColumnIsPinned(grid.columns[2], false, 1);
253-
254-
checkboxes[0].click();
255-
verifyColumnIsPinned(grid.columns[0], false, 0);
256-
257-
grid.columns[1].hidden = false;
258-
fix.detectChanges();
259-
260-
verifyCheckbox('ProductName', true, false, columnChooserElement, fix);
261-
verifyColumnIsPinned(grid.columns[1], true, 1);
262-
}));
263-
264240
it('- should size cells correctly when there is a large pinned templated column', fakeAsync(/** height/width setter rAF */() => {
265241
fix = TestBed.createComponent(ColumnPinningWithTemplateTestComponent);
266242
fix.detectChanges();

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

+3-40
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
293293
UIInteractions.simulateMouseEvent('mouseup', resizer, 450, 5);
294294
fixture.detectChanges();
295295

296-
expect(grid.columns[0].width).toEqual('300px');
296+
expect(grid.columns[0].width).toEqual('450px');
297297
expect(grid.columns[1].width).toEqual('100px');
298298

299299
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 300, 0);
@@ -305,7 +305,7 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
305305
UIInteractions.simulateMouseEvent('mouseup', resizer, 100, 5);
306306
fixture.detectChanges();
307307

308-
expect(grid.columns[0].width).toEqual('100px');
308+
expect(grid.columns[0].width).toEqual('250px');
309309
});
310310

311311
it('should resize columns with initial width of null.', async() => {
@@ -391,7 +391,7 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
391391
UIInteractions.simulateMouseEvent('mouseup', resizer, 350, 5);
392392
fixture.detectChanges();
393393

394-
expect(grid.columns[1].width).toEqual('150px');
394+
expect(grid.columns[1].width).toEqual('250px');
395395
});
396396

397397
it('should autoresize column on double click.', async() => {
@@ -465,43 +465,6 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
465465
expect(grid.columns[2].width).toEqual('92px');
466466
});
467467

468-
it('should autoresize pinned column on double click - edge case.', async() => {
469-
const fixture = TestBed.createComponent(LargePinnedColGridComponent);
470-
fixture.detectChanges();
471-
472-
const grid = fixture.componentInstance.grid;
473-
const headers: DebugElement[] = fixture.debugElement.queryAll(By.css(COLUMN_HEADER_GROUP_CLASS));
474-
475-
expect(grid.columns[0].width).toEqual('100px');
476-
expect(grid.columns[1].width).toEqual('100px');
477-
expect(grid.columns[2].width).toEqual('100px');
478-
479-
const resizeArea = headers[1].children[1].nativeElement;
480-
UIInteractions.simulateMouseEvent('dblclick', resizeArea, 0, 0);
481-
await wait(DEBOUNCE_TIME);
482-
fixture.detectChanges();
483-
484-
expect(grid.columns[0].width).toEqual('100px');
485-
expect(grid.columns[1].width).toEqual('100px');
486-
expect(grid.columns[2].width).toEqual('100px');
487-
488-
const headerResArea = headers[0].children[1].nativeElement;
489-
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 100, 0);
490-
await wait(DEBOUNCE_TIME);
491-
fixture.detectChanges();
492-
493-
const resizer = fixture.debugElement.queryAll(By.css(RESIZE_LINE_CLASS))[0].nativeElement;
494-
expect(resizer).toBeDefined();
495-
UIInteractions.simulateMouseEvent('mousemove', resizer, 450, 5);
496-
UIInteractions.simulateMouseEvent('mouseup', resizer, 450, 5);
497-
fixture.detectChanges();
498-
499-
const expetedWidth = grid.calcPinnedContainerMaxWidth - parseInt(grid.columns[1].width, 10) - parseInt(grid.columns[2].width, 10);
500-
expect(grid.columns[0].width).toEqual(expetedWidth + 'px');
501-
expect(grid.columns[1].width).toEqual('100px');
502-
expect(grid.columns[2].width).toEqual('100px');
503-
});
504-
505468
it('should fire onColumnResized with correct event args.', async() => {
506469
const fixture = TestBed.createComponent(GridFeaturesComponent);
507470
fixture.detectChanges();

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

-111
Original file line numberDiff line numberDiff line change
@@ -5599,96 +5599,6 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
55995599

56005600
expect(grid.filteredData).toBeNull();
56015601
}));
5602-
5603-
it('Move-left button is disabled when using it to pin a column and max pin area width is reached.',
5604-
fakeAsync(() => {
5605-
// Test prerequisites
5606-
grid.width = '500px';
5607-
fix.detectChanges();
5608-
grid.getColumnByName('ID').filterable = true;
5609-
grid.getColumnByName('ID').movable = true;
5610-
grid.cdr.detectChanges();
5611-
tick(100);
5612-
5613-
// Pin columns until maximum pin area width is reached.
5614-
const columns = ['ProductName', 'Downloads', 'Released'];
5615-
columns.forEach((columnField) => {
5616-
GridFunctions.clickExcelFilterIcon(fix, columnField);
5617-
fix.detectChanges();
5618-
GridFunctions.clickPinIconInExcelStyleFiltering(fix, false);
5619-
tick(200);
5620-
fix.detectChanges();
5621-
});
5622-
5623-
// Verify pinned columns and 'ID' column position.
5624-
const column = grid.columns.find((col) => col.field === 'ID');
5625-
GridFunctions.verifyColumnIsPinned(column, false, 3);
5626-
expect(GridFunctions.getColumnHeaderByIndex(fix, 3).innerText).toBe('ID');
5627-
5628-
// Open ESF for the 'ID' column and verify that 'move left' button is disabled.
5629-
GridFunctions.clickExcelFilterIcon(fix, 'ID');
5630-
fix.detectChanges();
5631-
const moveComponent = GridFunctions.getExcelFilteringMoveComponent(fix);
5632-
const moveLeftButton = GridFunctions.sortNativeElementsHorizontally(
5633-
Array.from(moveComponent.querySelectorAll('.igx-button--flat')))[0];
5634-
expect(moveLeftButton.classList.contains('igx-button--disabled')).toBe(true);
5635-
}));
5636-
5637-
it('Pin button is disabled when using it to pin a column and max pin area width is reached.',
5638-
fakeAsync(() => {
5639-
// Test prerequisites
5640-
grid.width = '500px';
5641-
fix.detectChanges();
5642-
grid.getColumnByName('ID').filterable = true;
5643-
grid.getColumnByName('ID').movable = true;
5644-
grid.cdr.detectChanges();
5645-
tick(100);
5646-
5647-
// Pin columns until maximum pin area width is reached.
5648-
const columns = ['ProductName', 'Downloads', 'Released'];
5649-
columns.forEach((columnField) => {
5650-
GridFunctions.clickExcelFilterIcon(fix, columnField);
5651-
fix.detectChanges();
5652-
GridFunctions.clickPinIconInExcelStyleFiltering(fix, false);
5653-
tick(200);
5654-
fix.detectChanges();
5655-
});
5656-
5657-
// Verify pinned columns and 'ID' column position.
5658-
const column = grid.columns.find((col) => col.field === 'ID');
5659-
GridFunctions.verifyColumnIsPinned(column, false, 3);
5660-
expect(GridFunctions.getColumnHeaderByIndex(fix, 3).innerText).toBe('ID');
5661-
5662-
// Open ESF for the 'ID' column and verify that 'pin column' button is disabled.
5663-
GridFunctions.clickExcelFilterIcon(fix, 'ID');
5664-
fix.detectChanges();
5665-
let pinButton = GridFunctions.getExcelFilteringPinContainer(fix);
5666-
expect(pinButton.classList.contains('igx-excel-filter__actions-pin--disabled')).toBe(true,
5667-
'pinButton should be disabled');
5668-
5669-
// Close ESF.
5670-
GridFunctions.clickCancelExcelStyleFiltering(fix);
5671-
fix.detectChanges();
5672-
5673-
grid.displayDensity = DisplayDensity.compact;
5674-
tick(200);
5675-
fix.detectChanges();
5676-
5677-
// Pin one more column, because there is enough space for one more in 'compact' density.
5678-
GridFunctions.clickExcelFilterIcon(fix, 'ReleaseDate');
5679-
fix.detectChanges();
5680-
GridFunctions.clickPinIconInExcelStyleFiltering(fix, true);
5681-
tick(200);
5682-
fix.detectChanges();
5683-
5684-
// Open ESF for the 'ID' column and verify that 'pin column' icon button is disabled.
5685-
GridFunctions.clickExcelFilterIcon(fix, 'ID');
5686-
fix.detectChanges();
5687-
const headerButtons = GridFunctions.getExcelFilteringHeaderIcons(fix);
5688-
pinButton = GridFunctions.sortNativeElementsHorizontally(Array.from(headerButtons))[0];
5689-
expect(pinButton.classList.contains('igx-button--disabled')).toBe(true,
5690-
'pinButton in header area should be disabled');
5691-
}));
56925602
});
56935603

56945604
describe(null, () => {
@@ -5792,27 +5702,6 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
57925702
fix.detectChanges();
57935703
}));
57945704

5795-
it('Should not pin column when its parent group cannot be pinned.', fakeAsync(() => {
5796-
// Test prerequisites
5797-
grid.width = '1000px';
5798-
fix.detectChanges();
5799-
tick(100);
5800-
5801-
// Pin the 'AnotherField' column.
5802-
GridFunctions.clickExcelFilterIcon(fix, 'AnotherField');
5803-
fix.detectChanges();
5804-
GridFunctions.clickPinIconInExcelStyleFiltering(fix, false);
5805-
tick(200);
5806-
fix.detectChanges();
5807-
5808-
// Verify that the 'ProductName' pin button is disabled, because its parent column cannot be pinned.
5809-
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
5810-
fix.detectChanges();
5811-
const pinButton = GridFunctions.getExcelFilteringPinContainer(fix);
5812-
expect(pinButton.classList.contains('igx-excel-filter__actions-pin--disabled')).toBe(true,
5813-
'pinButton should be disabled');
5814-
}));
5815-
58165705
it('Should pin column next to already pinned group by moving it to the left.', fakeAsync(() => {
58175706
// Test prerequisites
58185707
grid.width = '1000px';

projects/igniteui-angular/src/lib/grids/grid/grid.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
</div>
162162

163163
<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="isHorizontalScrollHidden">
164-
<div class="igx-grid__scroll-start" [style.width.px]='pinnedWidth' [hidden]="pinnedWidth === 0"></div>
164+
<div class="igx-grid__scroll-start" [style.width.px]='pinnedWidth' [style.min-width.px]='pinnedWidth' [hidden]="pinnedWidth === 0"></div>
165165
<div class="igx-grid__scroll-main" [style.width.px]='unpinnedWidth'>
166166
<ng-template igxGridFor [igxGridForOf]='[]' #scrollContainer>
167167
</ng-template>

0 commit comments

Comments
 (0)