1- import { Component , OnInit , Input , ChangeDetectorRef } from '@angular/core' ;
1+ import { Component , OnInit , Input , Output , EventEmitter , ChangeDetectorRef } from '@angular/core' ;
22import { trigger , style , animate , transition } from '@angular/animations' ;
33import { moveItemInArray } from '@angular/cdk/drag-drop' ;
44import { filter } from 'rxjs/internal/operators/filter' ;
@@ -55,6 +55,13 @@ interface ContextMenuData {
5555 data : any ;
5656}
5757
58+ interface DataChangeEventData {
59+ row : number ,
60+ column : number ,
61+ data : any
62+ }
63+
64+
5865@Component ( {
5966 selector : 'data-grid' ,
6067 templateUrl : './data-table.component.html' ,
@@ -77,6 +84,8 @@ interface ContextMenuData {
7784} )
7885export class DataTableComponent implements OnInit {
7986
87+
88+ @Output ( ) dataChanged = new EventEmitter < DataChangeEventData > ( ) ;
8089 @Input ( ) pagination ;
8190 private pageSize ;
8291 public dragTheme ;
@@ -121,7 +130,7 @@ export class DataTableComponent implements OnInit {
121130 public selectAllRows :boolean = false ;
122131
123132 // Convert row data to a 2D array.
124- createTableData1 ( filteredData ?:Array < any > , currentPage ?:number ) {
133+ createTableData ( filteredData ?:Array < any > , currentPage ?:number ) {
125134 this . TableRows = new Array < any > ( ) ;
126135 this . contextMenuData = [ ] ;
127136 if ( ! ( this . _rowData && this . _rowData . length ) ) {
@@ -437,7 +446,7 @@ export class DataTableComponent implements OnInit {
437446 this . previousIndex = undefined ;
438447 moveItemInArray ( this . columnDefs , event . previousIndex , event . currentIndex ) ;
439448 moveItemInArray ( this . FilterData , event . previousIndex , event . currentIndex ) ;
440- this . createTableData1 ( this . FilterData , this . CurrentPage ) ;
449+ this . createTableData ( this . FilterData , this . CurrentPage ) ;
441450
442451 }
443452
@@ -458,7 +467,7 @@ export class DataTableComponent implements OnInit {
458467 this . TableRows [ changeValue . row ] . data [ changeValue . column ] = changeValue . value ;
459468 this . pagedRows ( ) ;
460469 this . setPagedRow ( this . CurrentPage ) ;
461-
470+ this . dataChanged . emit ( changeValue ) ;
462471 }
463472
464473 private selectedRowsCount ( ) :number {
@@ -797,7 +806,7 @@ export class DataTableComponent implements OnInit {
797806 this . FilterRowCount = this . _rowData . length ;
798807 this . TotalRows = this . _rowData . length ;
799808 this . FilterData = new Array < FilterOptions > ( this . columnDefs . length ) ;
800- this . createTableData1 ( ) ;
809+ this . createTableData ( ) ;
801810 this . TotalPages = Math . ceil ( this . _rowData . length / this . pageSize ) ;
802811 this . ToRecord = this . pageSize ;
803812
0 commit comments