Skip to content

Commit 55fa779

Browse files
MKirovaMKirova
authored andcommitted
fix(igxGrid): Remove pinning limitations when pinned columns don't fit in available grid width. Removing tests that test for the limitation.
1 parent 736b686 commit 55fa779

13 files changed

+22
-538
lines changed

projects/igniteui-angular/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function (config) {
4141
colors: true,
4242
logLevel: config.LOG_INFO,
4343
autoWatch: true,
44-
browsers: ['Chrome'],
44+
browsers: ['ChromeHeadless'],
4545
singleRun: false
4646
});
4747
};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,9 +1694,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
16941694
*@hidden
16951695
*/
16961696
public get pinnable() {
1697-
const gridUnpinnedWidth = (this.grid as any).getUnpinnedWidth(true);
1698-
const elementWidth = this.parent ? parseInt(this.topLevelParent.width, 10) : parseInt(this.width, 10);
1699-
return (this.grid as any)._init || !((gridUnpinnedWidth - elementWidth) < this.grid.unpinnedAreaMinWidth);
1697+
return (this.grid as any)._init || !this.pinned;
17001698
}
17011699

17021700
/**

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,30 +3315,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
33153315
return DisplayDensity.compact;
33163316
}
33173317

3318-
/**
3319-
* Returns the maximum width of the container for the pinned `IgxColumnComponent`s.
3320-
* The width is 80% of the total grid width.
3321-
* ```typescript
3322-
* const maxPinnedColWidth = this.grid.calcPinnedContainerMaxWidth;
3323-
* ```
3324-
* @memberof IgxGridBaseComponent
3325-
*/
3326-
get calcPinnedContainerMaxWidth(): number {
3327-
return (this.calcWidth * 80) / 100;
3328-
}
3329-
3330-
/**
3331-
* Returns the minimum width of the container for the unpinned `IgxColumnComponent`s.
3332-
* The width is 20% of the total grid width.
3333-
* ```typescript
3334-
* const minUnpinnedColWidth = this.grid.unpinnedAreaMinWidth;
3335-
* ```
3336-
* @memberof IgxGridBaseComponent
3337-
*/
3338-
get unpinnedAreaMinWidth(): number {
3339-
return (this.calcWidth * 20) / 100;
3340-
}
3341-
33423318
/**
33433319
* Returns the current width of the container for the pinned `IgxColumnComponent`s.
33443320
* ```typescript
@@ -5553,7 +5529,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
55535529
let currentPinnedWidth = 0;
55545530
const pinnedColumns = [];
55555531
const unpinnedColumns = [];
5556-
const newUnpinnedCols = [];
55575532

55585533
this.calculateGridWidth();
55595534
this.resetCaches();
@@ -5574,16 +5549,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
55745549
if (this._columns[i].pinned && !this._columns[i].parent) {
55755550
// Pinned column. Check if with it the unpinned min width is exceeded.
55765551
const colWidth = parseInt(this._columns[i].width, 10);
5577-
if (currentPinnedWidth + colWidth > this.calcWidth - this.unpinnedAreaMinWidth) {
5578-
// unpinned min width is exceeded. Unpin the columns and add it to the unpinned collection.
5579-
this._columns[i].pinned = false;
5580-
unpinnedColumns.push(this._columns[i]);
5581-
newUnpinnedCols.push(this._columns[i]);
5582-
} else {
5583-
// unpinned min width is not exceeded. Keep it pinned and add it to the pinned collection.
5584-
currentPinnedWidth += colWidth;
5585-
pinnedColumns.push(this._columns[i]);
5586-
}
5552+
currentPinnedWidth += colWidth;
5553+
pinnedColumns.push(this._columns[i]);
55875554
} else if (this._columns[i].pinned && this._columns[i].parent) {
55885555
if (this._columns[i].topLevelParent.pinned) {
55895556
pinnedColumns.push(this._columns[i]);
@@ -5596,14 +5563,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
55965563
}
55975564
}
55985565

5599-
if (newUnpinnedCols.length) {
5600-
console.warn(
5601-
'igxGrid - The pinned area exceeds maximum pinned width. ' +
5602-
'The following columns were unpinned to prevent further issues:' +
5603-
newUnpinnedCols.map(col => '"' + col.header + '"').toString() + '. For more info see our documentation.'
5604-
);
5605-
}
5606-
56075566
// Assign the applicaple collections.
56085567
this._pinnedColumns = pinnedColumns;
56095568
this._unpinnedColumns = unpinnedColumns;

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

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,10 @@ export class IgxColumnResizingService {
6464
*/
6565
get restrictResizeMax(): number {
6666
const actualWidth = this.column.headerCell.elementRef.nativeElement.getBoundingClientRect().width;
67-
68-
if (this.column.pinned) {
69-
const pinnedMaxWidth = this.pinnedMaxWidth =
70-
this.column.grid.calcPinnedContainerMaxWidth - this.column.grid.getPinnedWidth(true) + actualWidth;
71-
72-
if (this.column.maxWidth && parseFloat(this.column.maxWidth) < pinnedMaxWidth) {
73-
this.pinnedMaxWidth = this.column.maxWidth;
74-
75-
return parseFloat(this.column.maxWidth) - actualWidth;
76-
} else {
77-
return pinnedMaxWidth - actualWidth;
78-
}
67+
if (this.column.maxWidth) {
68+
return parseFloat(this.column.maxWidth) - actualWidth;
7969
} else {
80-
if (this.column.maxWidth) {
81-
return parseFloat(this.column.maxWidth) - actualWidth;
82-
} else {
83-
return Number.MAX_SAFE_INTEGER;
84-
}
70+
return Number.MAX_SAFE_INTEGER;
8571
}
8672
}
8773

@@ -96,14 +82,7 @@ export class IgxColumnResizingService {
9682
const currentColWidth = this.column.headerCell.elementRef.nativeElement.getBoundingClientRect().width;
9783

9884
const size = this.column.getLargestCellWidth();
99-
100-
if (this.column.pinned) {
101-
const newPinnedWidth = this.column.grid.getPinnedWidth(true) - currentColWidth + parseFloat(size);
102-
103-
if (newPinnedWidth <= this.column.grid.calcPinnedContainerMaxWidth) {
104-
this.column.width = size;
105-
}
106-
} else if (this.column.maxWidth && (parseFloat(size) > parseFloat(this.column.maxWidth))) {
85+
if (this.column.maxWidth && (parseFloat(size) > parseFloat(this.column.maxWidth))) {
10786
this.column.width = parseFloat(this.column.maxWidth) + 'px';
10887
} else if (parseFloat(size) < parseFloat(this.column.minWidth)) {
10988
this.column.width = this.column.minWidth + 'px';
@@ -175,15 +154,6 @@ export class IgxColumnResizingService {
175154
const relativeColumns = column.getResizableColUnderEnd();
176155
const combinedSpan = relativeColumns.reduce((acc, col) => acc + col.spanUsed, 0);
177156

178-
if (column.pinned) {
179-
const pinnedWidth = this.column.grid.getPinnedWidth(true);
180-
const maxPinnedWidth = this.column.grid.calcPinnedContainerMaxWidth;
181-
182-
if (pinnedWidth + diff > maxPinnedWidth) {
183-
diff = maxPinnedWidth - pinnedWidth;
184-
}
185-
}
186-
187157
// Resize first those who might reach min/max width
188158
let columnsToResize = [...relativeColumns];
189159
let updatedDiff = diff;

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,7 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
533533
}
534534

535535
if (!this.cms.column.pinned && this.column.pinned) {
536-
const nextPinnedWidth = this.column.grid.getPinnedWidth(true) + parseFloat(this.cms.column.width);
537-
538-
if (nextPinnedWidth <= this.column.grid.calcPinnedContainerMaxWidth) {
539-
this.cms.icon.innerText = 'lock';
540-
} else {
541-
this.cms.icon.innerText = 'block';
542-
}
536+
this.cms.icon.innerText = 'lock';
543537
}
544538
} else {
545539
this.cms.icon.innerText = 'block';
@@ -594,20 +588,6 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
594588
target: this.column
595589
};
596590

597-
let nextPinnedWidth;
598-
if (this.column.pinned && !this.cms.column.pinned) {
599-
nextPinnedWidth = this.column.grid.getPinnedWidth(true) + parseFloat(this.cms.column.width);
600-
}
601-
602-
if ((nextPinnedWidth && nextPinnedWidth > this.column.grid.calcPinnedContainerMaxWidth) ||
603-
this.column.level !== this.cms.column.level ||
604-
this.column.parent !== this.cms.column.parent ||
605-
this.cms.cancelDrop) {
606-
this.cms.cancelDrop = false;
607-
this.column.grid.onColumnMovingEnd.emit(args);
608-
return;
609-
}
610-
611591
this.column.grid.moveColumn(this.cms.column, this.column, this._dropPos);
612592

613593
this.column.grid.draggedColumn = null;

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -742,51 +742,6 @@ describe('IgxGrid - multi-column headers #grid', () => {
742742
});
743743
}));
744744

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

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,42 +224,18 @@ describe('Column Pinning UI #grid', () => {
224224
expect(currentArgs.isPinned).toBe(false);
225225
}));
226226

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

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

237237
}));
238238

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

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

Lines changed: 3 additions & 40 deletions
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();

0 commit comments

Comments
 (0)