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 @@ -52,6 +52,7 @@ All notable changes for each version of this project will be documented in this
- 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`.
- Resizing a column that is drawn at its `minWidth` or `maxWidth` but has no `width` set now starts the first drag from the drawn width, for pixel and percentage widths. Previously the first drag was ignored because the resize started from the column's reported width. A drag that leaves the drawn width unchanged no longer emits `columnResized`, and `columnResized` now reports the drawn width as `prevWidth` (#18038).

## 22.3.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,18 @@ export class IgxColumnResizingService {
this.showResizer = false;
const diff = (event.clientX - this.startResizePos) / ratio;

// Releasing the handle without moving it must not change the column: without this,
// a column drawn at its minWidth would get that width assigned as its `width`.
if (diff === 0) {
this.zone.run(() => { });

this.isColumnResizing = false;
return;
}

const colWidth = this.column.width;
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
let currentColWidth = parseFloat(colWidth);
let currentColWidth = isPercentageWidth ? this.getResizeStartPercent(this.column) : this.getResizeStartWidth(this.column);
const actualWidth = this.getColumnHeaderRenderedWidth();
currentColWidth = Number.isNaN(currentColWidth) ? parseFloat(actualWidth as any) : currentColWidth;

Expand All @@ -133,8 +142,44 @@ export class IgxColumnResizingService {
this.isColumnResizing = false;
}

/**
* Returns the width a pixel resize should start from: the width the column is
* actually drawn at. A column without a set width reports its clamped default
* through `column.width` (e.g. 136px) while it is drawn wider through its
* `minWidth`; `calcWidth` holds that drawn width. Falls back to `column.width`
* when the calculated width is not finite.
*/
protected getResizeStartWidth(column: ColumnType): number {
const calcWidth = parseFloat(String(column.calcWidth));
return Number.isFinite(calcWidth) ? calcWidth : parseFloat(column.width);
}

/**
* Returns the percentage a percentage resize should start from: the width the column is
* actually drawn at, converted to a percentage of `grid.calcWidth`. A percentage column
* is drawn at its `minWidth` whenever its share of the grid is smaller than the `minWidth`
* and at its `maxWidth` whenever the share is larger. The conversion runs only when the
* column is drawn at a different width than its percentage: converting unconditionally
* is not exact (20% of a 641px grid comes back as `20.000000000000004%`), so an
* unconstrained column would get a slightly different stored value on every resize.
* Falls back to the percentage `width` when the grid has no width, the grid sizes its
* columns by their width sum, or the calculated width is not finite.
*/
protected getResizeStartPercent(column: ColumnType): number {
const percentWidth = parseFloat(column.width);
const gridWidth = column.grid.calcWidth;
const drawnWidth = parseFloat(String(column.calcWidth));
// In a grid without a width, percentage columns are drawn at their minimum whatever the percentage.
if (!gridWidth || column.grid.isColumnWidthSum || !Number.isFinite(drawnWidth)) {
return percentWidth;
}
// Compare in pixels: converting the drawn width back to a percentage is not exact.
const isDrawnAtWidth = Math.abs(drawnWidth - percentWidth / 100 * gridWidth) < 0.01;
return isDrawnAtWidth ? percentWidth : drawnWidth / gridWidth * 100;
}

protected _handlePixelResize(diff: number, column: ColumnType) {
const currentColWidth = parseFloat(column.width);
const currentColWidth = this.getResizeStartWidth(column);
const colMinWidth = column.minWidthPx;
const colMaxWidth = column.maxWidthPx;
if (currentColWidth + diff < colMinWidth) {
Expand All @@ -147,7 +192,7 @@ export class IgxColumnResizingService {
}

protected _handlePercentageResize(diff: number, column: ColumnType) {
const currentPercentWidth = parseFloat(column.width);
const currentPercentWidth = this.getResizeStartPercent(column);
const gridAvailableSize = column.grid.calcWidth;

const diffPercentage = (diff / gridAvailableSize) * 100;
Expand Down
Loading