Skip to content

Commit

Permalink
Merge pull request #6979 from IgniteUI/skrastev/hgrid-row-pinning
Browse files Browse the repository at this point in the history
Implement Row Pinning for igxHierarchicalGrid.
  • Loading branch information
ChronosSF authored Apr 13, 2020
2 parents 259d5a8 + ed6f4be commit 238d326
Show file tree
Hide file tree
Showing 25 changed files with 649 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@
@extend %igx-grid__td--editing !optional;
}

@include e(tr, $m: disabled) {
@extend %igx-grid__tr--disabled !optional;
}

@include e(td, $m: number) {
@extend %grid-cell-number !optional;
}
Expand Down Expand Up @@ -392,6 +396,10 @@
@extend %grid-cell--pinned--column-selected !optional;
}

@include e(td, $m: pinned-chip) {
@extend %grid-cell--pinned-chip !optional;
}

@include e(td-text) {
@extend %grid-cell-text !optional;
}
Expand Down Expand Up @@ -558,6 +566,11 @@
@extend %igx-grid__hierarchical-expander !optional;
}

@include e(hierarchical-expander, $m: empty) {
@extend %igx-grid__hierarchical-expander !optional;
@extend %igx-grid__hierarchical-expander--empty !optional;
}

@include e(hierarchical-expander, $m: header) {
@extend %igx-grid__hierarchical-expander--header !optional;
}
Expand Down Expand Up @@ -673,6 +686,11 @@
@extend %igx-grid__hierarchical-expander--cosy !optional;
}

@include e(hierarchical-expander, $m: empty) {
@extend %igx-grid__hierarchical-expander--cosy !optional;
@extend %igx-grid__hierarchical-expander--empty !optional;
}

@include e(hierarchical-expander, $m: push) {
@extend %igx-grid__hierarchical-expander--push--cosy !optional;
}
Expand All @@ -688,6 +706,10 @@
@extend %igx-grid__tree-cell-cosy--padding-level-#{$i} !optional;
}
}

@include e(td, $m: pinned-chip) {
@extend %grid-cell--pinned-chip--cosy !optional;
}
}

@include m(compact) {
Expand Down Expand Up @@ -772,6 +794,11 @@
@include e(hierarchical-expander) {
@extend %igx-grid__hierarchical-expander--compact !optional;
}

@include e(hierarchical-expander, $m: empty) {
@extend %igx-grid__hierarchical-expander--compact !optional;
@extend %igx-grid__hierarchical-expander--empty !optional;
}

@include e(hierarchical-expander, $m: push) {
@extend %igx-grid__hierarchical-expander--push--compact !optional;
Expand All @@ -788,6 +815,10 @@
@extend %igx-grid__tree-cell-compact--padding-level-#{$i} !optional;
}
}

@include e(td, $m: pinned-chip) {
@extend %grid-cell--pinned-chip--compact !optional;
}
}

@include _excel-filtering-partial();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
/// @param {Color} $cell-selected-background [null] - The selected cell background color.
/// @param {Color} $cell-selected-text-color [null] - The selected cell text color.
/// @param {Color} $cell-editing-background [null] - The background color of the cell being edited.
/// @param {Color} $cell-edited-value-color [null] - The text color of a sell that has been edited.
/// @param {Color} $cell-edited-value-color [null] - The text color of a cell that has been edited.
/// @param {Color} $cell-disabled-color [null] - The text color of a disabled cell.
///
/// @param {Color} $edit-mode-color [null] - The color applied around the row when in editing mode.
/// @param {Color} $edited-row-indicator [null] - The color applied to the edited row indicator line.
Expand Down Expand Up @@ -160,6 +161,7 @@
$cell-selected-text-color: null,
$cell-editing-background: null,
$cell-edited-value-color: null,
$cell-disabled-color: null,
$edit-mode-color: null,
$edited-row-indicator: null,
Expand Down Expand Up @@ -505,6 +507,8 @@
edited-row-indicator: $edited-row-indicator,
cell-edited-value-color: $cell-edited-value-color,

cell-disabled-color: $cell-disabled-color,

resize-line-color: $resize-line-color,

drop-indicator-color: $drop-indicator-color,
Expand Down Expand Up @@ -1352,6 +1356,12 @@
}
}

%igx-grid__tr--disabled {
%grid-cell-text {
color: --var($theme, 'cell-disabled-color');
}
}

%igx-grid__td--editing {
background: --var($theme, 'cell-editing-background') !important;
box-shadow: inset 0 0 0 rem(2px) --var($theme, 'edit-mode-color');
Expand Down Expand Up @@ -1407,6 +1417,17 @@
}
}

%grid-cell--pinned-chip {
margin-#{$right}: rem(12px);
}

%grid-cell--pinned-chip--cosy {
margin-#{$right}: rem(8px);
}

%grid-cell--pinned-chip--compact {
margin-#{$right}: rem(4px);
}

%grid-cell-header {
flex-flow: row nowrap;
Expand Down Expand Up @@ -2495,6 +2516,11 @@
@include if-rtl() {
transform: scaleX(-1);
}

&--empty {
cursor: default;
pointer-events: none;
}
}

%igx-grid__hierarchical-expander--cosy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
/// @prop {Map} edit-mode-color [igx-color: ('secondary', 500)] - The text color in edit mode.
/// @prop {Map} edited-row-indicator [igx-color: ('grays', 400)] - The indicator's color of edited row.
/// @prop {Map} cell-edited-value-color [igx-color: ('grays', 600)] - The color of cell edited value.
/// @prop {Map} cell-disabled-color [igx-color: ('grays', 500)] - The text color of a disabled cell.
/// @prop {Map} resize-line-color [igx-color: ('secondary', 500)] - The table header resize line color.
/// @prop {Map} drop-indicator-color [igx-color: ('secondary', 500)] - The color of the drop indicator.
/// @prop {Map} grouparea-background [igx-color: ('grays', 100), hexrgba: #fff] - The grid group area background color.
Expand Down Expand Up @@ -233,6 +234,10 @@ $_light-grid: extend(
igx-color: ('grays', 600)
),

cell-disabled-color: (
igx-color: ('grays', 500)
),

resize-line-color: (
igx-color: ('secondary', 500)
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<ng-template #defaultCell>
<igx-chip *ngIf="displayPinnedChip" class="igx-grid__td--pinned-chip" [disabled]="true" [displayDensity]="'compact'">Pinned</igx-chip>
<div igxTextHighlight style="pointer-events: none" [cssClass]="highlightClass" [activeCssClass]="activeHighlightClass" [groupName]="gridID"
[value]="formatter ? formatter(value) : column.dataType === 'number' ? (value | igxdecimal: grid.locale) : column.dataType === 'date' ? (value | igxdate: grid.locale) : value"
[row]="rowData" [column]="this.column.field" [containerClass]="'igx-grid__td-text'"
Expand Down
11 changes: 9 additions & 2 deletions projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
*/
@HostBinding('attr.aria-readonly')
get readonly(): boolean {
return !this.column.editable;
return !this.editable;
}

get gridRowSpan(): number {
Expand Down Expand Up @@ -523,7 +523,14 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
* Returns whether the cell is editable.
*/
get editable(): boolean {
return this.column.editable;
return this.column.editable && !this.row.disabled;
}

/**
* @hidden
*/
public get displayPinnedChip() {
return this.row.pinned && this.row.disabled && this.visibleColumnIndex === 0 && !(this.column as any).cellTemplate;
}

@ViewChild('defaultCell', { read: TemplateRef, static: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export interface RowType {
checkboxElement: IgxCheckboxComponent;
rowID: any;
rowData: any;
disabled: boolean;
rowSelectable: boolean;
index: number;
gridID: string;
added: boolean;
pinned: boolean;
deleted: boolean;
selected: boolean;
focused: boolean;
Expand Down
17 changes: 14 additions & 3 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5140,6 +5140,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
return this.verticalScrollContainer.igxForOf;
}

/**
* Returns the currently transformed paged/filtered/sorted/grouped pinned data, displayed in the grid.
* @example
* ```typescript
* const pinnedDataView = this.grid.pinnedDataView;
* ```
*/
get pinnedDataView(): any[] {
return this.pinnedRows.map(row => row.rowData);
}

/**
* Get current selection state.
* @example
Expand Down Expand Up @@ -5344,8 +5355,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
columnsArray.forEach((col) => {
if (col) {
const key = headers ? col.header || col.field : col.field;
record[key] = formatters && col.formatter ? col.formatter(source[row][col.field])
: source[row][col.field];
const value = source[row].ghostRecord ? source[row].recordRef[col.field] : source[row][col.field];
record[key] = formatters && col.formatter ? col.formatter(value) : value;
}
});
}
Expand Down Expand Up @@ -5380,7 +5391,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
* If `headers` is enabled, it will use the column header (if any) instead of the column field.
*/
public getSelectedData(formatters = false, headers = false) {
const source = this.dataView;
const source = this.isRowPinningToTop ? [...this.pinnedDataView, ...this.dataView] : [...this.dataView, ...this.pinnedDataView];
return this.extractDataFromSelection(source, formatters, headers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class IgxGridNavigationService {
break;
case 'enter':
case 'f2':
if (!this.isDataRow(rowIndex)) { break; }
const cell = this.grid.getCellByColumnVisibleIndex(this.activeNode.row, this.activeNode.column);
if (!this.isDataRow(rowIndex) || !cell.editable) { break; }
this.grid.crudService.enterEditMode(cell);
break;
case 'escape':
Expand All @@ -114,8 +114,8 @@ export class IgxGridNavigationService {
case ' ':
case 'spacebar':
case 'space':
if (this.grid.isRowSelectable && this.isDataRow(rowIndex)) {
const rowObj = this.grid.getRowByIndex(this.activeNode.row);
const rowObj = this.grid.getRowByIndex(this.activeNode.row);
if (this.grid.isRowSelectable && this.isDataRow(rowIndex) && !rowObj.disabled) {
rowObj && rowObj.selected ? this.grid.selectionService.deselectRow(rowObj.rowID, event) :
this.grid.selectionService.selectRowById(rowObj.rowID, false, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
[tabindex]="-1"
[checked]="selected"
[readonly]="true"
[disabled]="deleted"
[disabled]="disabled || deleted"
disableRipple="true"
[disableTransitions]="grid.disableTransitions"
[aria-label]="rowCheckboxAriaLabel">
Expand Down
25 changes: 20 additions & 5 deletions projects/igniteui-angular/src/lib/grids/grid/row-pinning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IgxGridTransaction } from '../tree-grid';
import { IgxTransactionService } from '../../services';
import { GridSummaryFunctions } from '../../test-utils/grid-functions.spec';
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
import { IgxPaginatorComponent } from '../../paginator/paginator.component';

describe('Row Pinning #grid', () => {
const FIXED_ROW_CONTAINER = '.igx-grid__tr--pinned ';
Expand Down Expand Up @@ -401,26 +402,40 @@ describe('Row Pinning #grid', () => {
grid.paging = true;
grid.perPage = 5;
fix.detectChanges();
let row = grid.getRowByIndex(1);
row.pin();
const paginator = fix.debugElement.query(By.directive(IgxPaginatorComponent));
expect(paginator.componentInstance.totalPages).toEqual(6);

grid.getRowByIndex(1).pin();
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(1);
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
expect(pinRowContainer.length).toBe(1);

expect(grid.dataView.length).toBe(4);
expect(paginator.componentInstance.totalPages).toEqual(6);

grid.getRowByIndex(3).pin();
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(2);
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
expect(pinRowContainer.length).toBe(1);
expect(grid.dataView.length).toBe(3);
expect(paginator.componentInstance.totalPages).toEqual(5);

// unpin
row = grid.getRowByIndex(0);
row.unpin();
grid.getRowByIndex(0).unpin();
fix.detectChanges();

grid.getRowByIndex(0).unpin();
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(0);
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
expect(pinRowContainer.length).toBe(0);

expect(grid.dataView.length).toBe(5);
expect(paginator.componentInstance.totalPages).toEqual(6);
});

it('should apply sorting to both pinned and unpinned rows.', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IgxGridCellComponent } from '../cell.component';
import { GridBaseAPIService } from '../api.service';
import { ChangeDetectorRef, ElementRef, ChangeDetectionStrategy, Component,
OnInit, HostListener, NgZone } from '@angular/core';
OnInit, HostListener, NgZone, HostBinding } from '@angular/core';
import { IgxHierarchicalGridComponent } from './hierarchical-grid.component';
import { IgxGridSelectionService, IgxGridCRUDService } from '../selection/selection.service';
import { HammerGesturesManager } from '../../core/touch';
Expand All @@ -11,11 +11,10 @@ import { PlatformUtil } from '../../core/utils';
changeDetection: ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
selector: 'igx-hierarchical-grid-cell',
templateUrl: './../cell.component.html',
templateUrl: '../cell.component.html',
providers: [HammerGesturesManager]
})
export class IgxHierarchicalGridCellComponent extends IgxGridCellComponent implements OnInit {

// protected hSelection;
protected _rootGrid;

Expand Down
Loading

0 comments on commit 238d326

Please sign in to comment.