Skip to content

Commit

Permalink
fix(grid): update delete row function (#10519)
Browse files Browse the repository at this point in the history
* fix(grid): update delete row function

* fix(grid): update row index selection

* fix(grid): add after-view-init implementation in sample
  • Loading branch information
Svetloslav15 authored Nov 17, 2021
1 parent 24f1698 commit 6ed5a11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/app/grid-column-selection/grid-column-selection.sample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, OnInit, Pipe, PipeTransform } from '@angular/core';
import { Component, ViewChild, OnInit, Pipe, PipeTransform, AfterViewInit, ChangeDetectorRef } from '@angular/core';
import {
IgxGridComponent,
OverlaySettings,
Expand All @@ -21,7 +21,7 @@ import { SAMPLE_DATA } from '../shared/sample-data';
templateUrl: 'grid-column-selection.sample.html'
})

export class GridColumnSelectionSampleComponent implements OnInit {
export class GridColumnSelectionSampleComponent implements OnInit, AfterViewInit {
@ViewChild('grid1', { static: true }) public grid1: IgxGridComponent;
@ViewChild('grid', { static: true }) public grid: IgxGridComponent;

Expand Down Expand Up @@ -64,10 +64,16 @@ export class GridColumnSelectionSampleComponent implements OnInit {
closeOnOutsideClick: true
};

constructor(private cdr: ChangeDetectorRef) {}

public log(event) {
console.log(event);
}

public ngAfterViewInit() {
this.cdr.detectChanges();
}

public ngOnInit(): void {
this.displayDensities = [
{ label: 'comfortable', selected: this.density === 'comfortable', togglable: true },
Expand Down
11 changes: 7 additions & 4 deletions src/app/grid/grid.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ export class GridSampleComponent implements OnInit, AfterViewInit {
}

public deleteRow() {
this.selectedRow = Object.assign({}, this.selectedCell.Row);
this.grid1.deleteRow(this.selectedCell.rowIndex);
this.selectedCell = {};
this.snax.open(`Row with ID ${this.selectedRow.record.ID} was deleted`);
if (this.selectedCell.cell) {
const rowIndex = this.selectedCell.cell.row.index;
const row = this.grid1.getRowByIndex(rowIndex);
row.delete();
this.snax.open(`Row with ID ${rowIndex} was deleted`);
this.selectedCell = {};
}
}

public restore() {
Expand Down

0 comments on commit 6ed5a11

Please sign in to comment.