Skip to content

Commit 94f9d0d

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Merge from master.
2 parents 2568c06 + 710523f commit 94f9d0d

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master, 9.1.x ]
8+
branches: [ master, 9.1.x, 10.0.x ]
99
pull_request:
10-
branches: [ master, 9.1.x ]
10+
branches: [ master, 9.1.x, 10.0.x ]
1111

1212
jobs:
1313
build:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5+
## 10.1.0
6+
7+
### New Features
8+
- `IgxColumn`
9+
- Added `byHeader` parameter to the `autosize` method which specifies if the autosizing should be based only on the header content width.
10+
511
## 10.0.0
612

713
### General

projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
2020
public destroyed;
2121

2222
private _afterViewInit = false;
23+
private _scrollNativeSize: number;
2324

2425
ngAfterViewInit() {
2526
this._afterViewInit = true;
@@ -29,7 +30,9 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
2930
onScroll(event) {
3031
this.scrollAmount = event.target.scrollTop || event.target.scrollLeft;
3132
}
32-
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef) { }
33+
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef) {
34+
this._scrollNativeSize = this.calculateScrollNativeSize();
35+
}
3336

3437
get nativeElement() {
3538
return this.elementRef.nativeElement;
@@ -54,6 +57,10 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
5457
}
5558

5659
public get scrollNativeSize() {
60+
return this._scrollNativeSize;
61+
}
62+
63+
public calculateScrollNativeSize() {
5764
const div = document.createElement('div');
5865
const style = div.style;
5966
style.width = '100px';

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,10 +1788,11 @@ export class IgxColumnComponent implements AfterContentInit {
17881788
* column.autosize();
17891789
* ```
17901790
* @memberof IgxColumnComponent
1791+
* @param byHeader Set if column should be autized based only on the header content
17911792
*/
1792-
public autosize() {
1793+
public autosize(byHeader = false) {
17931794
if (!this.columnGroup) {
1794-
const size = this.getAutoSize();
1795+
const size = this.getAutoSize(byHeader);
17951796
this.width = size;
17961797
this.grid.reflow();
17971798
}
@@ -1800,8 +1801,9 @@ export class IgxColumnComponent implements AfterContentInit {
18001801
/**
18011802
* @hidden
18021803
*/
1803-
public getAutoSize() {
1804-
const size = this.getLargestCellWidth();
1804+
public getAutoSize(byHeader = false) {
1805+
const size = !byHeader ? this.getLargestCellWidth() :
1806+
(Object.values(this.getHeaderCellWidths()).reduce((a, b) => a + b) + 'px');
18051807
const gridAvailableSize = this.grid.calcWidth;
18061808
let newWidth;
18071809
const isPercentageWidth = this.width && typeof this.width === 'string' && this.width.indexOf('%') !== -1;
@@ -1825,6 +1827,36 @@ export class IgxColumnComponent implements AfterContentInit {
18251827
return this._calcWidth;
18261828
}
18271829

1830+
1831+
/**
1832+
* @hidden
1833+
* Returns the width and padding of a header cell.
1834+
*/
1835+
public getHeaderCellWidths() {
1836+
const range = this.grid.document.createRange();
1837+
let headerWidth;
1838+
if (this.headerTemplate && this.headerCell.elementRef.nativeElement.children[0].children.length > 0) {
1839+
headerWidth = Math.max(...Array.from(this.headerCell.elementRef.nativeElement.children[0].children)
1840+
.map((child) => getNodeSizeViaRange(range, child)));
1841+
} else {
1842+
headerWidth = getNodeSizeViaRange(range, this.headerCell.elementRef.nativeElement.children[0]);
1843+
}
1844+
1845+
if (this.sortable || this.filterable) {
1846+
headerWidth += this.headerCell.elementRef.nativeElement.children[1].getBoundingClientRect().width;
1847+
}
1848+
1849+
const headerStyle = this.grid.document.defaultView.getComputedStyle(this.headerCell.elementRef.nativeElement);
1850+
const headerPadding = parseFloat(headerStyle.paddingLeft) + parseFloat(headerStyle.paddingRight) +
1851+
parseFloat(headerStyle.borderRightWidth);
1852+
1853+
// Take into consideration the header group element, since column pinning applies borders to it if its not a columnGroup.
1854+
const headerGroupStyle = this.grid.document.defaultView.getComputedStyle(this.headerGroup.element.nativeElement);
1855+
const borderSize = !this.parent ? parseFloat(headerGroupStyle.borderRightWidth) + parseFloat(headerGroupStyle.borderLeftWidth) : 0;
1856+
1857+
return { width: Math.ceil(headerWidth), padding: Math.ceil(headerPadding + borderSize)};
1858+
}
1859+
18281860
/**
18291861
* @hidden
18301862
* Returns the size (in pixels) of the longest currently visible cell, including the header cell.
@@ -1851,29 +1883,14 @@ export class IgxColumnComponent implements AfterContentInit {
18511883
const index = cellsContentWidths.indexOf(Math.max(...cellsContentWidths));
18521884
const cellStyle = this.grid.document.defaultView.getComputedStyle(this.cells[index].nativeElement);
18531885
const cellPadding = parseFloat(cellStyle.paddingLeft) + parseFloat(cellStyle.paddingRight) +
1854-
parseFloat(cellStyle.borderRightWidth);
1886+
parseFloat(cellStyle.borderLeftWidth) + parseFloat(cellStyle.borderRightWidth);
18551887

18561888
largest.set(Math.max(...cellsContentWidths), cellPadding);
18571889
}
18581890

18591891
if (this.headerCell) {
1860-
let headerCell;
1861-
if (this.headerTemplate && this.headerCell.elementRef.nativeElement.children[0].children.length > 0) {
1862-
headerCell = Math.max(...Array.from(this.headerCell.elementRef.nativeElement.children[0].children)
1863-
.map((child) => getNodeSizeViaRange(range, child)));
1864-
} else {
1865-
headerCell = getNodeSizeViaRange(range, this.headerCell.elementRef.nativeElement.children[0]);
1866-
}
1867-
1868-
if (this.sortable || this.filterable) {
1869-
headerCell += this.headerCell.elementRef.nativeElement.children[1].getBoundingClientRect().width;
1870-
}
1871-
1872-
const headerStyle = this.grid.document.defaultView.getComputedStyle(this.headerCell.elementRef.nativeElement);
1873-
const headerPadding = parseFloat(headerStyle.paddingLeft) + parseFloat(headerStyle.paddingRight) +
1874-
parseFloat(headerStyle.borderRightWidth);
1875-
largest.set(headerCell, headerPadding);
1876-
1892+
const headerCellWidths = this.getHeaderCellWidths();
1893+
largest.set(headerCellWidths.width, headerCellWidths.padding);
18771894
}
18781895

18791896
const largestCell = Math.max(...Array.from(largest.keys()));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
383383
expect(column.width).toEqual('63px');
384384
}));
385385

386+
it('should autosize column programmatically based only on header.', fakeAsync(() => {
387+
const column = fixture.componentInstance.grid.columnList.filter(c => c.field === 'ReleaseDate')[0];
388+
expect(column.width).toEqual('100px');
389+
390+
column.autosize(true);
391+
fixture.detectChanges();
392+
393+
expect(column.width).toEqual('112px');
394+
}));
395+
386396
it('should autosize pinned column programmatically.', fakeAsync(/** height/width setter rAF */() => {
387397
const column = grid.getColumnByName('Released');
388398
expect(column.width).toEqual('100px');

0 commit comments

Comments
 (0)