Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ All notable changes for each version of this project will be documented in this
- `IgxTreeComponent`
- The navigation keys combined with a modifier no longer move the focus, expand, collapse, select or activate nodes. The browser default runs. Previously the tree ignored most modifiers and handled these keys as the plain keys. `Ctrl` + `ArrowUp` / `ArrowDown` (move the focus without activating the node), `Shift` + `Space` (select a range) and `*` with or without `Shift` keep working.

### Bug Fixes

- `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent`
- Setting `pinned` pins and unpins a column that has no `width` and a `minWidth` below 136px. Previously, when the grid had no space left for the column, it stayed in place and its `width` returned `-Infinitypx` (#18039).
- Setting `pinned` on a hidden column that has no `width` pins the column when it is shown. Previously, when every visible column had a `width` or was held at its `minWidth` or `maxWidth`, the grid `columnWidth` and the hidden column `width` returned `Infinitypx`, so the column was shown in the unpinned area while `pinned` was `true` (#18039).
- A column that has no `width` and is held at its `maxWidth` shrinks again when the grid gets narrower. Previously it kept its `maxWidth`, the grid showed a horizontal scrollbar, and its `width` returned `Infinitypx`.

## 22.3.3

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2753,15 +2753,14 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
const currentCalcWidth = this.defaultWidth || this.grid.getPossibleColumnWidth();
this._calcWidth = this.getConstrainedSizePx(parseFloat(currentCalcWidth));
} else {
let possibleColumnWidth = '';
if (!this.widthSetByUser && this.userSetMinWidthPx && this.userSetMinWidthPx < this.grid.minColumnWidth) {
possibleColumnWidth = this.defaultWidth = this.grid.getPossibleColumnWidth();
// A constrained column counts as sized and would not get its share of the remaining space
this.widthConstrained = false;
this._calcWidth = this.getConstrainedSizePx(parseFloat(this.grid.getPossibleColumnWidth()));
this.defaultWidth = this._calcWidth + 'px';
} else {
possibleColumnWidth = this.width;
this._calcWidth = this.getConstrainedSizePx(parseFloat(this.width));
}

const currentCalcWidth = parseFloat(possibleColumnWidth);
this._calcWidth = this.getConstrainedSizePx(currentCalcWidth);
}
this.calcPixelWidth = parseFloat(this._calcWidth.toString());
}
Expand Down
74 changes: 74 additions & 0 deletions projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
LargePinnedColGridComponent,
NullColumnsComponent,
MinWidthColumnsComponent,
MaxWidthColumnComponent,
LargeMinWidthColumnComponent,
ColGridComponent,
ColPercentageGridComponent,
AutosizeFilteringGridComponent
Expand Down Expand Up @@ -1218,6 +1220,52 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
expect(grid.columnList.get(2).width).toEqual('90px');
expect(grid.columnList.get(3).width).toEqual('90px');
});

it('should size columns to their `minWidth` when the grid has no space left for them - #18039.', async () => {
const fixture = TestBed.createComponent(MinWidthColumnsComponent);
fixture.detectChanges();
const grid = fixture.componentInstance.grid;

// Too narrow for the 3 columns without a width, even at their 50px minWidth
grid.width = '200px';
fixture.detectChanges();
await fixture.whenStable();

expect(grid.columnList.get(0).width).toEqual('130px');
for (const column of grid.columnList.toArray().slice(1)) {
expect(column.width).toEqual('50px');
expect(column.calcPixelWidth).toEqual(50);
}
});

it('should size a column with only a `maxWidth` to the free space when the grid gets narrower.', async () => {
const fixture = TestBed.createComponent(MaxWidthColumnComponent);
fixture.detectChanges();
const grid = fixture.componentInstance.grid;
const column = grid.getColumnByName('CompanyName');
expect(column.calcPixelWidth).toEqual(300);

grid.width = '400px';
fixture.detectChanges();
await fixture.whenStable();

expect(column.calcPixelWidth).toEqual(200);
expect(grid.hasHorizontalScroll()).toBe(false);
});

it('should grow a column held at its `minWidth` when the grid gets wider.', async () => {
const fixture = TestBed.createComponent(LargeMinWidthColumnComponent);
fixture.detectChanges();
const grid = fixture.componentInstance.grid;
const column = grid.getColumnByName('CompanyName');
expect(column.calcPixelWidth).toEqual(300);

grid.width = '1200px';
fixture.detectChanges();
await fixture.whenStable();

expect(column.calcPixelWidth).toEqual(1000);
});
});

describe('Resizer tests: ', () => {
Expand Down Expand Up @@ -1402,6 +1450,32 @@ export class MinWidthColumnsComponent implements OnInit {
}
}

@Component({
template: GridTemplateStrings.declareGrid(`width="1000px" height="300px"`, ``, `<igx-column field="ID" width="200px"></igx-column>
<igx-column field="CompanyName" maxWidth="300px"></igx-column>`),
changeDetection: ChangeDetectionStrategy.Eager,
imports: [IgxGridComponent, IgxColumnComponent]
})
export class MaxWidthColumnComponent {
@ViewChild(IgxGridComponent, { static: true })
public grid: IgxGridComponent;

public data = SampleTestData.contactInfoData().slice(0, 2);
}

@Component({
template: GridTemplateStrings.declareGrid(`width="400px" height="300px"`, ``, `<igx-column field="ID" width="200px"></igx-column>
<igx-column field="CompanyName" minWidth="300px"></igx-column>`),
changeDetection: ChangeDetectionStrategy.Eager,
imports: [IgxGridComponent, IgxColumnComponent]
})
export class LargeMinWidthColumnComponent {
@ViewChild(IgxGridComponent, { static: true })
public grid: IgxGridComponent;

public data = SampleTestData.contactInfoData().slice(0, 2);
}

@Component({
template: GridTemplateStrings.declareGrid(`width="400px" height="600px" [allowFiltering]="true"`, ``, `<igx-column [field]="'Items'" [width]="'40px'" dataType="string" [filterable]="true"></igx-column>
<igx-column [field]="'ID'" [width]="'50px'" [header]="'ID'" [filterable]="true"></igx-column>
Expand Down
11 changes: 10 additions & 1 deletion projects/igniteui-angular/grids/grid/src/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5821,10 +5821,14 @@ export abstract class IgxGridBaseDirective implements GridType,
const combinedBlocksSize = colsPerBlock.reduce((acc, item) => acc + item.length, 0);
colsPerBlock.forEach(blockCols => visibleCols = visibleCols.concat(blockCols) as MRLColumnSizeInfo[]);

const columnsWithSetWidths = this.hasColumnLayouts ?
let columnsWithSetWidths = this.hasColumnLayouts ?
visibleCols.filter(c => c.widthSetByUser) :
visibleChildColumns.filter(c => (c.widthSetByUser || c.widthConstrained) && c.width !== 'fit-content');

if (!this.hasColumnLayouts && !this.isColumnWidthSum && columnsWithSetWidths.length === visibleChildColumns.length) {
columnsWithSetWidths = visibleChildColumns.filter(c => c.widthSetByUser);
}

const columnsToSize = this.hasColumnLayouts ?
combinedBlocksSize - columnsWithSetWidths.length :
visibleChildColumns.length - columnsWithSetWidths.length;
Expand Down Expand Up @@ -5859,6 +5863,11 @@ export abstract class IgxGridBaseDirective implements GridType,
return '0px';
}

// Avoids an `Infinitypx` width for a hidden column without a width
if (columnsToSize <= 0 && !this.hasColumnLayouts) {
return this.minColumnWidth + 'px';
}

computedWidth -= this.featureColumnsWidth();

const columnWidth = !Number.isFinite(sumExistingWidths) ?
Expand Down
158 changes: 156 additions & 2 deletions projects/igniteui-angular/grids/grid/src/grid.pinning.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { GridSelectionMode, IgxGridHeaderRowComponent, IgxGridMRLNavigationService, IPinningConfig, RowPinningPosition } from 'igniteui-angular/grids/core';
import { GridSelectionMode, IgxColumnComponent, IgxGridHeaderRowComponent, IgxGridMRLNavigationService, IPinningConfig, RowPinningPosition } from 'igniteui-angular/grids/core';
import { wait, UIInteractions } from '../../../test-utils/ui-interactions.spec';
import { CELL_PINNED_CLASS, GRID_MRL_BLOCK, GRID_SCROLL_CLASS, GridFunctions, GridSelectionFunctions, GridSummaryFunctions, HEADER_PINNED_CLASS, PINNED_SUMMARY } from '../../../test-utils/grid-functions.spec';
import { GridFeaturesComponent, GridPinningMRLComponent, MRLTestComponent, MultiColumnHeadersComponent, MultiColumnHeadersWithGroupingComponent, PinningComponent, PinOnBothSidesInitComponent, PinOnInitAndSelectionComponent } from '../../../test-utils/grid-samples.spec';
Expand All @@ -24,7 +25,10 @@ describe('IgxGrid - Column Pinning #grid', () => {
GridFeaturesComponent,
MultiColumnHeadersWithGroupingComponent,
GridPinningMRLComponent,
PinOnBothSidesInitComponent
PinOnBothSidesInitComponent,
PinningMinWidthComponent,
PinningHiddenColumnComponent,
PinningHiddenConstrainedColumnComponent
],
providers: [
IgxGridMRLNavigationService
Expand Down Expand Up @@ -1043,4 +1047,154 @@ describe('IgxGrid - Column Pinning #grid', () => {
});
});

describe('Column with no width and a minWidth below the default minimum (#18039)', () => {
let fix;
let grid: IgxGridComponent;

beforeEach(() => {
fix = TestBed.createComponent(PinningMinWidthComponent);
fix.detectChanges();
grid = fix.componentInstance.grid;
});

it('should pin and unpin the column through the pinned input', () => {
fix.componentInstance.publisherPinned = true;
fix.detectChanges();
expect(grid.pinnedColumns.map(c => c.field)).toEqual(['publisher']);

fix.componentInstance.publisherPinned = false;
fix.detectChanges();
expect(grid.pinnedColumns.length).toBe(0);
expect(grid.unpinnedColumns.map(c => c.field)).toEqual(['name', 'publisher', 'gender', 'race', 'skinColor', 'eyeColor', 'hairColor']);
});

it('should unpin the column through the pinned property after pinning it with pin()', () => {
const column = grid.getColumnByName('publisher');
expect(column.pin()).toBe(true);
fix.detectChanges();

column.pinned = false;
fix.detectChanges();
expect(grid.pinnedColumns.length).toBe(0);
expect(column.pinned).toBe(false);
});

it('should pin the column through the pinned input while it is hidden', () => {
grid.width = '1400px';
const column = grid.getColumnByName('publisher');
column.hidden = true;
fix.detectChanges();
expect(column.width).toEqual('136px');
expect(column.calcPixelWidth).toEqual(136);

fix.componentInstance.publisherPinned = true;
fix.detectChanges();
column.hidden = false;
fix.detectChanges();
expect(grid.pinnedColumns.map(c => c.field)).toEqual(['publisher']);

fix.componentInstance.publisherPinned = false;
fix.detectChanges();
expect(grid.pinnedColumns.length).toBe(0);
});
});

describe('Hidden column with no width when every visible column has a width (#18039)', () => {
it('should pin and unpin the column through the pinned input after it is shown', () => {
const fix = TestBed.createComponent(PinningHiddenColumnComponent);
fix.detectChanges();
const grid = fix.componentInstance.grid;
const column = grid.getColumnByName('gender');
expect(grid.columnWidth).toEqual('136px');
expect(column.width).toEqual('136px');

fix.componentInstance.genderPinned = true;
fix.detectChanges();
fix.componentInstance.genderHidden = false;
fix.detectChanges();
expect(grid.pinnedColumns.map(c => c.field)).toEqual(['gender']);

fix.componentInstance.genderPinned = false;
fix.detectChanges();
expect(grid.pinnedColumns.length).toBe(0);
});
});

describe('Hidden column with no width when the other column without a width is held at its maxWidth (#18039)', () => {
it('should pin and unpin the column through the pinned input after it is shown', () => {
const fix = TestBed.createComponent(PinningHiddenConstrainedColumnComponent);
fix.detectChanges();
const grid = fix.componentInstance.grid;
const column = grid.getColumnByName('gender');
expect(grid.getColumnByName('publisher').calcPixelWidth).toEqual(100);
expect(Number.isFinite(parseFloat(grid.columnWidth))).toBe(true);
expect(Number.isFinite(parseFloat(column.width))).toBe(true);

fix.componentInstance.genderPinned = true;
fix.detectChanges();
fix.componentInstance.genderHidden = false;
fix.detectChanges();
expect(grid.pinnedColumns.map(c => c.field)).toEqual(['gender']);

fix.componentInstance.genderPinned = false;
fix.detectChanges();
expect(grid.pinnedColumns.length).toBe(0);
});
});

});

@Component({
template: `
<igx-grid #grid [data]="data" width="700px" height="500px">
<igx-column field="name" width="300px"></igx-column>
<igx-column field="publisher" minWidth="135px" [pinned]="publisherPinned"></igx-column>
<igx-column field="gender" width="150px"></igx-column>
<igx-column field="race" width="150px"></igx-column>
<igx-column field="skinColor" width="150px"></igx-column>
<igx-column field="eyeColor" width="150px"></igx-column>
<igx-column field="hairColor" width="150px"></igx-column>
</igx-grid>`,
changeDetection: ChangeDetectionStrategy.Eager,
imports: [IgxGridComponent, IgxColumnComponent]
})
class PinningMinWidthComponent {
@ViewChild('grid', { static: true }) public grid: IgxGridComponent;
public publisherPinned = false;
public data = [
{ name: 'Batman', publisher: 'DC Comics', gender: 'Male', race: 'Human', skinColor: '-', eyeColor: 'blue', hairColor: 'black' },
{ name: 'Storm', publisher: 'Marvel Comics', gender: 'Female', race: 'Mutant', skinColor: '-', eyeColor: 'brown', hairColor: 'white' }
];
}

@Component({
template: `
<igx-grid #grid [data]="data" width="1000px" height="500px">
<igx-column field="name" width="200px"></igx-column>
<igx-column field="publisher" width="200px"></igx-column>
<igx-column field="gender" [hidden]="genderHidden" [pinned]="genderPinned"></igx-column>
</igx-grid>`,
changeDetection: ChangeDetectionStrategy.Eager,
imports: [IgxGridComponent, IgxColumnComponent]
})
class PinningHiddenColumnComponent {
@ViewChild('grid', { static: true }) public grid: IgxGridComponent;
public genderHidden = true;
public genderPinned = false;
public data = [
{ name: 'Batman', publisher: 'DC Comics', gender: 'Male' },
{ name: 'Storm', publisher: 'Marvel Comics', gender: 'Female' }
];
}

@Component({
template: `
<igx-grid #grid [data]="data" width="1000px" height="500px">
<igx-column field="name" width="130px"></igx-column>
<igx-column field="publisher" minWidth="50px" maxWidth="100px"></igx-column>
<igx-column field="gender" [hidden]="genderHidden" [pinned]="genderPinned"></igx-column>
</igx-grid>`,
changeDetection: ChangeDetectionStrategy.Eager,
imports: [IgxGridComponent, IgxColumnComponent]
})
class PinningHiddenConstrainedColumnComponent extends PinningHiddenColumnComponent {}
Loading
Loading