Skip to content

Commit a9ece5f

Browse files
committed
feat(pinning): Inital poc for pinning columns to right #5879
1 parent 2516834 commit a9ece5f

File tree

11 files changed

+313
-34
lines changed

11 files changed

+313
-34
lines changed

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-component.scss

+9
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
@extend %grid-cell--pinned-last !optional;
246246
}
247247

248+
@include e(th, $m: pinned-first) {
249+
@extend %grid-cell--pinned-first !optional;
250+
}
251+
248252
@include e(th, $m: fw) {
249253
@extend %grid-cell--fixed-width !optional;
250254
}
@@ -327,6 +331,11 @@
327331
@extend %grid-cell--pinned-last !optional;
328332
}
329333

334+
@include e(td, $m: pinned-first) {
335+
@extend %grid-cell--pinned !optional;
336+
@extend %grid-cell--pinned-first !optional;
337+
}
338+
330339
@include e(td, $m: pinned-end) {
331340
@extend %grid-cell-pinned--end !optional;
332341
}

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-theme.scss

+8
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,14 @@
12651265
}
12661266
}
12671267

1268+
%grid-cell--pinned-first {
1269+
border-#{$left}: map-get($cell-pin, 'style') map-get($cell-pin, 'color') !important;
1270+
1271+
&%grid-cell--editing {
1272+
border-#{$left}: map-get($cell-pin, 'style') --var($theme, 'cell-selected-background') !important;
1273+
}
1274+
}
1275+
12681276
%grid-cell-header {
12691277
flex-flow: row nowrap;
12701278
justify-content: space-between;

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

+8
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
330330
@HostBinding('class.igx-grid__td--pinned-last')
331331
lastPinned = false;
332332

333+
/**
334+
* @hidden
335+
* @internal
336+
*/
337+
@Input()
338+
@HostBinding('class.igx-grid__td--pinned-first')
339+
firstPinned = false;
340+
333341
/**
334342
* Returns whether the cell is in edit mode.
335343
*/

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

+133-3
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,46 @@ export class IgxColumnComponent implements AfterContentInit {
590590
}
591591
}
592592

593+
/**
594+
* Gets whether the column is `pinnedToRight`.
595+
* ```typescript
596+
* let isPinnedToRight = this.column.pinnedToRight;
597+
* ```
598+
* @memberof IgxColumnComponent
599+
*/
600+
@WatchColumnChanges()
601+
@Input()
602+
public get pinnedToRight(): boolean {
603+
return this._pinnedToRight;
604+
}
605+
/**
606+
* Sets whether the column is pinned.
607+
* Default value is `false`.
608+
* ```html
609+
* <igx-column [pinnedToRight] = "true"></igx-column>
610+
* ```
611+
*
612+
* Two-way data binding.
613+
* ```html
614+
* <igx-column [(pinnedToRight)] = "model.columns[0].isPinnedToRight"></igx-column>
615+
* ```
616+
* @memberof IgxColumnComponent
617+
*/
618+
public set pinnedToRight(value: boolean) {
619+
if (this._pinnedToRight !== value) {
620+
if (this.grid && this.width && !isNaN(parseInt(this.width, 10))) {
621+
value ? this.pinToRight() : this.unpin();
622+
return;
623+
}
624+
/* No grid/width available at initialization. `initPinning` in the grid
625+
will re-init the group (if present)
626+
*/
627+
this._unpinnedIndex = this.grid ? this.grid.columns.filter(x => !x._pinnedToRight).indexOf(this) : 0;
628+
this._pinnedToRight = value;
629+
this.pinnedChange.emit(this._pinnedToRight);
630+
}
631+
}
632+
593633
/**
594634
*@hidden
595635
*/
@@ -904,6 +944,7 @@ export class IgxColumnComponent implements AfterContentInit {
904944
}
905945
const unpinnedColumns = this.grid.unpinnedColumns.filter(c => !c.columnGroup);
906946
const pinnedColumns = this.grid.pinnedColumns.filter(c => !c.columnGroup);
947+
const pinnedRightColumns = this.grid.pinnedRightColumns.filter(c => !c.columnGroup);
907948
let col = this;
908949
let vIndex = -1;
909950

@@ -914,11 +955,14 @@ export class IgxColumnComponent implements AfterContentInit {
914955
return this.parent.childrenVisibleIndexes.find(x => x.column === this).index;
915956
}
916957

917-
if (!this.pinned) {
958+
if (!this.pinned && !this.pinnedToRight) {
918959
const indexInCollection = unpinnedColumns.indexOf(col);
919960
vIndex = indexInCollection === -1 ? -1 : pinnedColumns.length + indexInCollection;
920-
} else {
961+
} else if (this.pinned) {
921962
vIndex = pinnedColumns.indexOf(col);
963+
} else {
964+
const indexInCollection = pinnedRightColumns.indexOf(this);
965+
vIndex = indexInCollection === -1 ? -1 : pinnedColumns.length + unpinnedColumns.length + indexInCollection;
922966
}
923967
this._vIndex = vIndex;
924968
return vIndex;
@@ -988,6 +1032,17 @@ export class IgxColumnComponent implements AfterContentInit {
9881032
get isLastPinned(): boolean {
9891033
return this.grid.pinnedColumns[this.grid.pinnedColumns.length - 1] === this;
9901034
}
1035+
1036+
get isFirstPinned(): boolean {
1037+
return this.grid.pinnedRightColumns[0] === this;
1038+
}
1039+
1040+
get rightPinnedOffset(): string {
1041+
return this.pinnedToRight ?
1042+
-(this.grid.pinnedWidth + this.grid.rightPinnedWidth) + 'px' :
1043+
null;
1044+
}
1045+
9911046
get gridRowSpan(): number {
9921047
return this.rowEnd && this.rowStart ? this.rowEnd - this.rowStart : 1;
9931048
}
@@ -1127,6 +1182,10 @@ export class IgxColumnComponent implements AfterContentInit {
11271182
*@hidden
11281183
*/
11291184
protected _pinned = false;
1185+
/**
1186+
*@hidden
1187+
*/
1188+
protected _pinnedToRight = false;
11301189
/**
11311190
*@hidden
11321191
*/
@@ -1545,6 +1604,73 @@ export class IgxColumnComponent implements AfterContentInit {
15451604
this.grid.filteringService.refreshExpressions();
15461605
return true;
15471606
}
1607+
/**
1608+
* Pins the column at the provided index in the pinned area to the right. Defaults to index `0` if not provided.
1609+
* Returns `true` if the column is successfully pinned. Returns `false` if the column cannot be pinned.
1610+
* Column cannot be pinned if:
1611+
* - Is already pinned
1612+
* - index argument is out of range
1613+
* - The pinned area exceeds 80% of the grid width
1614+
* ```typescript
1615+
* let success = this.column.pin();
1616+
* ```
1617+
* @memberof IgxColumnComponent
1618+
*/
1619+
public pinToRight(index?: number): boolean {
1620+
if (this.grid) {
1621+
this.grid.endEdit(true);
1622+
}
1623+
if (this._pinnedToRight) {
1624+
return false;
1625+
}
1626+
1627+
if (this.parent && !this.parent.pinnedToRight) {
1628+
return this.topLevelParent.pinToRight(index);
1629+
}
1630+
1631+
const grid = (this.grid as any);
1632+
const hasIndex = index !== undefined;
1633+
if (hasIndex && (index < 0 || index >= grid.pinnedToRightColumns.length)) {
1634+
return false;
1635+
}
1636+
1637+
if (!this.parent && !this.pinnable) {
1638+
return false;
1639+
}
1640+
1641+
this._pinnedToRight = true;
1642+
this.pinnedChange.emit(this._pinnedToRight);
1643+
this._unpinnedIndex = grid._unpinnedColumns.indexOf(this);
1644+
index = index !== undefined ? index : grid._pinnedRightColumns.length;
1645+
const targetColumn = grid._pinnedRightColumns[index];
1646+
const args = { column: this, insertAtIndex: index, isPinned: true };
1647+
grid.onColumnPinning.emit(args);
1648+
1649+
if (grid._pinnedRightColumns.indexOf(this) === -1) {
1650+
grid._pinnedRightColumns.splice(args.insertAtIndex, 0, this);
1651+
1652+
if (grid._unpinnedColumns.indexOf(this) !== -1) {
1653+
grid._unpinnedColumns.splice(grid._unpinnedColumns.indexOf(this), 1);
1654+
}
1655+
}
1656+
1657+
if (hasIndex) {
1658+
grid._moveColumns(this, targetColumn);
1659+
}
1660+
1661+
if (this.columnGroup) {
1662+
this.allChildren.forEach(child => child.pinToRight());
1663+
grid.reinitPinStates();
1664+
}
1665+
1666+
grid.resetCaches();
1667+
grid.notifyChanges();
1668+
if (this.columnLayoutChild) {
1669+
this.grid.columns.filter(x => x.columnLayout).forEach(x => x.populateVisibleIndexes());
1670+
}
1671+
this.grid.filteringService.refreshExpressions();
1672+
return true;
1673+
}
15481674
/**
15491675
* Unpins the column and place it at the provided index in the unpinned area. Defaults to index `0` if not provided.
15501676
* Returns `true` if the column is successfully unpinned. Returns `false` if the column cannot be unpinned.
@@ -1560,7 +1686,7 @@ export class IgxColumnComponent implements AfterContentInit {
15601686
if (this.grid) {
15611687
this.grid.endEdit(true);
15621688
}
1563-
if (!this._pinned) {
1689+
if (!this._pinned && !this._pinnedToRight) {
15641690
return false;
15651691
}
15661692

@@ -1577,6 +1703,7 @@ export class IgxColumnComponent implements AfterContentInit {
15771703
index = (index !== undefined ? index :
15781704
this._unpinnedIndex !== undefined ? this._unpinnedIndex : this.index);
15791705
this._pinned = false;
1706+
this._pinnedToRight = false;
15801707
this.pinnedChange.emit(this._pinned);
15811708

15821709
const targetColumn = grid._unpinnedColumns[index];
@@ -1585,6 +1712,9 @@ export class IgxColumnComponent implements AfterContentInit {
15851712
if (grid._pinnedColumns.indexOf(this) !== -1) {
15861713
grid._pinnedColumns.splice(grid._pinnedColumns.indexOf(this), 1);
15871714
}
1715+
if (grid._pinnedRightColumns.indexOf(this) !== -1) {
1716+
grid._pinnedRightColumns.splice(grid._pinnedRightColumns.indexOf(this), 1);
1717+
}
15881718

15891719
if (hasIndex) {
15901720
grid._moveColumns(this, targetColumn);

0 commit comments

Comments
 (0)