Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes for each version of this project will be documented in this
- In `IgxSimpleComboComponent`, "Add item" no longer appears focused before it is reached with the keyboard, for example right after typing text that matches no item or when the list reopens (#17992).
- `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent`
- Auto-sizing columns with `width="auto"` no longer throws when a column group is partly scrolled out of view and one of its child columns with a cell template has no rendered cells. Such a column is now measured when it is scrolled into view.
- 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).
- `provideIgniteIntl()`
- The US time zone abbreviations `UT`, `EDT`, `CST`, `CDT`, `MDT`, `PST` and `PDT`, in any letter case, are formatted with fixed offsets, as with the Angular date pipe. This applies to date formatting such as `IColumnPipeArgs.timezone` and the date pipe. A format that shows the zone shows the offset, such as `GMT-8` for `PST`. Previously `UT`, `EDT`, `CDT`, `MDT` and `PDT` produced the unformatted date text, and `CST` and `PST` were shifted by daylight saving time. `EST` and `MST` are formatted as before (#18031).
- `IgxPivotGridComponent`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2753,15 +2753,26 @@ 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 column without a width and with a `minWidth` below the grid minimum can shrink down to its `minWidth`
const sizeToMinWidth = !this.widthSetByUser && this.userSetMinWidthPx && this.userSetMinWidthPx < this.grid.minColumnWidth;
let currentCalcWidth: number;
if (sizeToMinWidth) {
// Size this column with the columns without a width. Once constrained, it would count as sized,
// and as the only column without a width it would get a non-finite width (a division by zero).
this.widthConstrained = false;
currentCalcWidth = parseFloat(this.grid.getPossibleColumnWidth());
// A hidden column is not sized with the visible columns, so its possible width can still be non-finite
if (!Number.isFinite(currentCalcWidth)) {
currentCalcWidth = this.userSetMinWidthPx;
}
} else {
possibleColumnWidth = this.width;
currentCalcWidth = parseFloat(this.width);
}

const currentCalcWidth = parseFloat(possibleColumnWidth);
this._calcWidth = this.getConstrainedSizePx(currentCalcWidth);
if (sizeToMinWidth) {
this.defaultWidth = this._calcWidth + 'px';
}
}
this.calcPixelWidth = parseFloat(this._calcWidth.toString());
}
Expand Down
17 changes: 17 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 @@ -1218,6 +1218,23 @@ 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);
}
});
});

describe('Resizer tests: ', () => {
Expand Down
82 changes: 80 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,8 @@ describe('IgxGrid - Column Pinning #grid', () => {
GridFeaturesComponent,
MultiColumnHeadersWithGroupingComponent,
GridPinningMRLComponent,
PinOnBothSidesInitComponent
PinOnBothSidesInitComponent,
PinningMinWidthComponent
],
providers: [
IgxGridMRLNavigationService
Expand Down Expand Up @@ -1043,4 +1045,80 @@ 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', () => {
// The columns with a width leave space, and the hidden column is the only one without a width
grid.width = '1400px';
const column = grid.getColumnByName('publisher');
column.hidden = true;
fix.detectChanges();
expect(column.width).toEqual('135px');
expect(column.calcPixelWidth).toEqual(135);

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);
});
});

});

@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' }
];
}
Loading