Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add row basic functionality #8093

Merged
merged 25 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f523639
feat(addRow): Added sample, cell template and a pipe
mddragnev Aug 29, 2020
613f766
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular…
mddragnev Sep 4, 2020
3dcb294
feat(addRow): Add navigation handling and snackbar
mddragnev Sep 4, 2020
e2b8163
Merge branch 'master' into mdragnev/add-row-feat
mddragnev Sep 9, 2020
e977022
chore(*): fix failing tests
mddragnev Sep 9, 2020
625ef4d
chore(*): resolve change requests and changes from spec doc
mddragnev Sep 10, 2020
0f8b86f
chore(*): resolving change requests
mddragnev Sep 11, 2020
ed7f336
chore(*): Adding icons from the extended icons repo
mddragnev Sep 11, 2020
9dc40e5
chore(*): fix failing build
mddragnev Sep 11, 2020
08b595a
Merge branch 'master' into mdragnev/add-row-feat
ChronosSF Sep 14, 2020
57860ee
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular…
mddragnev Sep 17, 2020
607a60c
chore(*): change snackbar showing logic and navigation scenario
mddragnev Sep 17, 2020
6a4e762
chore(*): fix failing tests
mddragnev Sep 17, 2020
350d851
chore(*): fix snackbar navigation and show cases
mddragnev Sep 17, 2020
90798e4
chore(*): fix failing build
mddragnev Sep 17, 2020
abc1321
chore(*): subscribe only once to addrow snackbar action
mddragnev Sep 18, 2020
c14c8be
chore(*): fix failing tests
mddragnev Sep 18, 2020
02cbd5b
Merge branch 'master' into mdragnev/add-row-feat
ChronosSF Sep 21, 2020
5d76cd3
Merge branch 'master' into mdragnev/add-row-feat
ChronosSF Sep 21, 2020
c2cbfa4
Merge branch 'master' into mdragnev/add-row-feat
3phase Sep 23, 2020
2f01d9b
chore(*): Add logic so that grid with MRL works as expected
mddragnev Sep 23, 2020
ead3eae
Merge branch 'mdragnev/add-row-feat' of https://github.com/IgniteUI/i…
mddragnev Sep 23, 2020
d6d202f
chore(*): fixing failing test and sass selector
mddragnev Sep 24, 2020
0113d7f
chore(*): change snackbar class name selector name changed
mddragnev Sep 24, 2020
f2f3cb5
Merge branch 'master' into mdragnev/add-row-feat
ChronosSF Sep 24, 2020
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
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@angular/platform-browser": "^10.1.0",
"@angular/platform-browser-dynamic": "^10.1.0",
"@angular/router": "^10.1.0",
"@igniteui/material-icons-extended": "^2.3.0",
"@types/hammerjs": "^2.0.36",
"@types/source-map": "0.5.2",
"classlist.js": "^1.1.20150312",
Expand All @@ -62,8 +63,8 @@
"lodash.merge": "^4.6.2",
"resize-observer-polyfill": "^1.5.1",
"rxjs": "^6.6.3",
"tslib": "^2.0.0",
"setimmediate": "^1.0.5",
"tslib": "^2.0.0",
"web-animations-js": "^2.3.2",
"zone.js": "~0.10.3"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Directive, Inject } from '@angular/core';
import { IgxActionStripComponent } from '../action-strip.component';
import { IgxRowDirective } from '../../grids/public_api';
import { IgxGridIconService } from '../../grids/common/grid-icon.service';
import { IgxIconService } from '../../icon/icon.service';

@Directive({
selector: '[igxGridActionsBase]'
})
export class IgxGridActionsBaseDirective {
constructor(@Inject(IgxActionStripComponent) protected strip: IgxActionStripComponent, protected iconService: IgxGridIconService) { }
constructor(@Inject(IgxActionStripComponent) protected strip: IgxActionStripComponent, protected iconService: IgxIconService) { }

/**
* Getter to be used in template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<button igxButton="icon" [disabled]="disabled" igxRipple (click)="startEdit($event)">
<igx-icon>edit</igx-icon>
</button>
<button *ngIf="addRow" igxButton="icon" [disabled]="disabled" igxRipple (click)="addChild($event)">
<igx-icon fontSet="imx-icons" name="add-row"></igx-icon>
</button>
<button igxButton="icon" [disabled]="disabled" class="igx-action-strip__delete" igxRipple (click)="deleteRow($event)">
<igx-icon >delete</igx-icon>
<igx-icon>delete</igx-icon>
</button>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, HostBinding } from '@angular/core';
import { Component, HostBinding, Input } from '@angular/core';
import { IgxGridActionsBaseDirective } from './grid-actions-base.directive';
import { showMessage } from '../../core/deprecateDecorators';
import { addRow } from '@igniteui/material-icons-extended';

@Component({
selector: 'igx-grid-editing-actions',
Expand All @@ -18,6 +19,23 @@ export class IgxGridEditingActionsComponent extends IgxGridActionsBaseDirective
public cssClass = 'igx-action-strip__editing-actions';

private isMessageShown = false;
private _addRow = false;
private iconsRendered = false;

/**
* An input to enable/disable action strip row adding button
*/
@Input()
public set addRow(value: boolean) {
this._addRow = value;
}
public get addRow(): boolean {
if (!this.iconsRendered) {
this.registerIcons();
this.iconsRendered = true;
}
return this._addRow;
}

/**
* Enter row or cell edit mode depending the grid rowEditable option
Expand Down Expand Up @@ -69,6 +87,23 @@ export class IgxGridEditingActionsComponent extends IgxGridActionsBaseDirective
this.strip.hide();
}

public addChild(event?): void {
if (event) {
event.stopPropagation();
}
if (!this.isRow(this.strip.context)) {
return;
}
const context = this.strip.context;
const grid = context.grid;
if (!grid.rowEditable) {
console.warn('The grid must be in row edit mode to perform row adding!');
return;
}
grid.beginAddRowByIndex(context.rowID, context.index);
this.strip.hide();
}

/**
* Getter if the row is disabled
* @hidden
Expand All @@ -80,4 +115,12 @@ export class IgxGridEditingActionsComponent extends IgxGridActionsBaseDirective
}
return this.strip.context.disabled;
}

/**
* @hidden
* @internal
*/
private registerIcons() {
this.iconService.addSvgIconFromText(addRow.name, addRow.value, 'imx-icons');
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<ng-container *ngIf="isRowContext">
<button *ngIf="inPinnedArea && pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
<igx-icon fontSet="pinning-actions-icons" name="jump_down"></igx-icon>
<igx-icon fontSet="imx-icons" name="jump-down"></igx-icon>
</button>
<button *ngIf="inPinnedArea && !pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
<igx-icon fontSet="pinning-actions-icons" name="jump_up"></igx-icon>
<igx-icon fontSet="imx-icons" name="jump-up"></igx-icon>
</button>
<button *ngIf="!pinned" igxRipple igxButton="icon" (click)="pin($event)">
<igx-icon fontSet="pinning-icons" name="pin"></igx-icon>
<igx-icon fontSet="imx-icons" name="pin-left"></igx-icon>
</button>
<button *ngIf="pinned" igxRipple igxButton="icon" (click)="unpin($event)">
<igx-icon fontSet="pinning-icons" name="unpin"></igx-icon>
<igx-icon fontSet="imx-icons" name="unpin-left"></igx-icon>
</button>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('igxGridPinningActions #grid ', () => {
let pinIcon, unpinIcon;
actionStrip.show(grid.rowList.first);
fixture.detectChanges();
pinIcon = fixture.debugElement.query(By.css(`igx-icon[name=pin]`));
unpinIcon = fixture.debugElement.query(By.css(`igx-icon[name=unpin]`));
pinIcon = fixture.debugElement.query(By.css(`igx-icon[name=pin-left]`));
unpinIcon = fixture.debugElement.query(By.css(`igx-icon[name=unpin-left]`));
expect(unpinIcon).toBeNull();
pinIcon.parent.triggerEventHandler('click', new Event('click'));
actionStrip.hide();
Expand All @@ -49,8 +49,8 @@ describe('igxGridPinningActions #grid ', () => {

actionStrip.show(grid.pinnedRows[0]);
fixture.detectChanges();
pinIcon = fixture.debugElement.query(By.css(`igx-icon[name=pin]`));
unpinIcon = fixture.debugElement.query(By.css(`igx-icon[name=unpin]`));
pinIcon = fixture.debugElement.query(By.css(`igx-icon[name=pin-left]`));
unpinIcon = fixture.debugElement.query(By.css(`igx-icon[name=unpin-left]`));
expect(pinIcon).toBe(null);
unpinIcon.parent.triggerEventHandler('click', new Event('click'));
actionStrip.hide();
Expand All @@ -65,7 +65,7 @@ describe('igxGridPinningActions #grid ', () => {
actionStrip.show(grid.pinnedRows[0]);
fixture.detectChanges();

const jumpIcon = fixture.debugElement.query(By.css(`igx-icon[name=jump_down]`));
const jumpIcon = fixture.debugElement.query(By.css(`igx-icon[name=jump-down]`));
jumpIcon.parent.triggerEventHandler('click', new Event('click'));
await wait();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, HostBinding } from '@angular/core';
import { IgxGridActionsBaseDirective } from './grid-actions-base.directive';
import { GridIconsFeature } from '../../grids/common/enums';
import { PINNING_ACTIONS_ICONS_FONT_SET, PINNING_ACTIONS_ICONS, } from './grid-pinning-actions-icons';
import { PINNING_ICONS_FONT_SET, PINNING_ICONS } from '../../grids/pinning/pinning-icons';
import { pinLeft, unpinLeft, jumpDown, jumpUp } from '@igniteui/material-icons-extended';
@Component({
selector: 'igx-grid-pinning-actions',
templateUrl: 'grid-pinning-actions.component.html',
Expand Down Expand Up @@ -119,8 +117,10 @@ export class IgxGridPinningActionsComponent extends IgxGridActionsBaseDirective
const context = this.strip.context;
const grid = context.grid;
if (grid) {
this.iconService.registerSVGIcons(GridIconsFeature.RowPinning, PINNING_ICONS, PINNING_ICONS_FONT_SET);
this.iconService.registerSVGIcons(GridIconsFeature.RowPinningActions, PINNING_ACTIONS_ICONS, PINNING_ACTIONS_ICONS_FONT_SET);
this.iconService.addSvgIconFromText(pinLeft.name, pinLeft.value, 'imx-icons');
this.iconService.addSvgIconFromText(unpinLeft.name, unpinLeft.value, 'imx-icons');
this.iconService.addSvgIconFromText(jumpDown.name, jumpDown.value, 'imx-icons');
this.iconService.addSvgIconFromText(jumpUp.name, jumpDown.value, 'imx-icons');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface IGridResourceStrings {
igx_grid_pinning_check_all_label?: string;
igx_grid_pinning_uncheck_all_label?: string;
igx_grid_toolbar_actions_filter_prompt?: string;
igx_grid_snackbar_addrow_label?: string;
igx_grid_snackbar_addrow_actiontext?: string;
}

export const GridResourceStringsEN: IGridResourceStrings = {
Expand Down Expand Up @@ -195,5 +197,7 @@ export const GridResourceStringsEN: IGridResourceStrings = {
igx_grid_hiding_uncheck_all_label: 'Show All',
igx_grid_pinning_check_all_label: 'Pin All',
igx_grid_pinning_uncheck_all_label: 'Unpin All',
igx_grid_toolbar_actions_filter_prompt: 'Filter columns list ...'
igx_grid_toolbar_actions_filter_prompt: 'Filter columns list ...',
igx_grid_snackbar_addrow_label: 'Row added',
igx_grid_snackbar_addrow_actiontext: 'SHOW'
};
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@
@extend %igx-grid__row-editing-outlet !optional;
}

@include e(addrow-snackbar) {
@extend %igx-grid__addrow-snackbar !optional;
}

@include e(filtering-cell) {
@extend %igx-grid__filtering-cell !optional;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,13 @@
}
}

%igx-grid__addrow-snackbar {
position: absolute;
z-index: 5;
left: 35%;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property should be the interpolated version of the $left variable for RTL compatibility purposes.

Suggested change
left: 35%;
#{$left}: 35%;

Also, are you sure you want to use percentages as the unit to set the position of the snackbar? If yes, how did you come up with those numbers?

bottom: 25%;
}

%igx-grid__filtering-cell {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ describe('igxExpansionPanel', () => {
expect(grid.attributes.getNamedItem('ng-reflect-auto-generate').nodeValue).toEqual('true');
expect(grid.attributes.getNamedItem('ng-reflect-width').nodeValue).toEqual(fixture.componentInstance.width);
expect(grid.attributes.getNamedItem('ng-reflect-height').nodeValue).toEqual(fixture.componentInstance.height);
expect(grid.childElementCount).toEqual(7);
expect(grid.childElementCount).toEqual(8); // +1 because of add row snackbar
}));
it('Should apply all appropriate classes on combo initialization_image + text content', fakeAsync(() => {
const fixture: ComponentFixture<IgxExpansionPanelImageComponent> = TestBed.createComponent(IgxExpansionPanelImageComponent);
Expand Down
21 changes: 20 additions & 1 deletion projects/igniteui-angular/src/lib/grids/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
return -1;
}
const data = dataCollection ?? this.get_all_data(grid.transactions.enabled);
return grid.primaryKey ? data.findIndex(record => record[grid.primaryKey] === rowID) : data.indexOf(rowID);
return grid.primaryKey ? data.findIndex(record => record.recordRef ? record.recordRef[grid.primaryKey] === rowID
: record[grid.primaryKey] === rowID) : data.indexOf(rowID);
}

public get_row_by_key(rowSelector: any): IgxRowDirective<IgxGridBaseDirective & GridType> {
Expand Down Expand Up @@ -136,6 +137,24 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
}
}

public submit_add_value() {
const cell = this.grid.crudService.cell;
if (cell) {
this.update_add_cell(cell, cell.editValue);
this.escape_editMode();
}
}

public update_add_cell(cell: IgxCell, value: any) {
cell.editValue = value;

if (isEqual(cell.value, cell.editValue)) {
return;
}
const data = cell.rowData;
this.updateData(this.grid, cell.id.rowID, data, cell.rowData, reverseMapper(cell.column.field, cell.editValue));
}

update_cell(cell: IgxCell, value: any) {
cell.editValue = value;
const args = cell.createEditEventArgs();
Expand Down
13 changes: 13 additions & 0 deletions projects/igniteui-angular/src/lib/grids/cell.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
>{{ value ? "check" : "close" }}</igx-icon
>
</ng-template>
<ng-template #addRowCell let-cell="cell">
<div igxTextHighlight class="igx-grid__td-text" style="pointer-events: none"
[cssClass]="highlightClass"
[activeCssClass]="activeHighlightClass"
[groupName]="gridID"
[value]="formatter ? (value | columnFormatter:formatter) : 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'"
[metadata]="searchMetadata">{{
value ? value : column.field
}}</div>
</ng-template>
<ng-template #inlineEditor let-cell="cell">
<ng-container *ngIf="column.dataType === 'string'">
<igx-input-group displayDensity="compact">
Expand Down
21 changes: 20 additions & 1 deletion projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
* @memberof IgxGridCellComponent
*/
get template(): TemplateRef<any> {
if (this.grid.rowEditable && this.row.addRow) {
return this.addMode ? this.inlineEditorTemplate : this.addRowCellTemplate;
}
if (this.editMode) {
const inlineEditorTemplate = this.column.inlineEditorTemplate;
return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
Expand Down Expand Up @@ -354,6 +357,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
@HostBinding('class.igx-grid__td--editing')
editMode = false;

/**
* Returns whether the cell is in add mode
*/
@Input()
addMode = false;

/**
* Sets/get the `role` property of the cell.
Expand Down Expand Up @@ -517,6 +525,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
@ViewChild('inlineEditor', { read: TemplateRef, static: true })
protected inlineEditorTemplate: TemplateRef<any>;

@ViewChild('addRowCell', { read: TemplateRef, static: true})
protected addRowCellTemplate: TemplateRef<any>;

@ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
protected set highlight(value: IgxTextHighlightDirective) {
this._highlight = value;
Expand Down Expand Up @@ -631,7 +642,12 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {

if (this.editable && editMode && !this.row.deleted) {
if (editableCell) {
this.gridAPI.update_cell(editableCell, editableCell.editValue);
if (this.row.addRow) {
this.gridAPI.update_add_cell(editableCell, editableCell.editValue);
this.row.rowData = editableCell.rowData;
} else {
this.gridAPI.update_cell(editableCell, editableCell.editValue);
}
/* This check is related with the following issue #6517:
* when edit cell that belongs to a column which is sorted and press tab,
* the next cell in edit mode is with wrong value /its context is not updated/;
Expand Down Expand Up @@ -790,6 +806,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
// prevent double-tap to zoom on iOS
(event as HammerInput).preventDefault();
}
if (this.grid.rowEditable && this.row.addRow) {
this.crudService.begin(this);
}
if (this.editable && !this.editMode && !this.row.deleted) {
this.crudService.begin(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ export interface ColumnType {
topLevelParent?: ColumnType;
parent?: ColumnType;
hasLastPinnedChildColumn: boolean;

getGridTemplate(isRow: boolean, isIE: boolean): string;
}
Loading