@@ -83,7 +83,14 @@ export class DataTableComponent implements OnInit {
8383
8484 @Input ( ) theme ;
8585 @Input ( ) columnDefs :Column [ ] ;
86- @Input ( ) rowData ;
86+ private _rowData ;
87+ get rowData ( ) :Array < any > {
88+ return this . _rowData ;
89+ }
90+ @Input ( ) set rowData ( data :Array < any > ) {
91+ this . _rowData = data ;
92+ this . init ( ) ;
93+ }
8794 @Input ( ) rowSelection :boolean = true ;
8895 @Input ( ) commonSearch :boolean = false ;
8996 public isMoving :boolean = false ;
@@ -117,22 +124,22 @@ export class DataTableComponent implements OnInit {
117124 createTableData1 ( filteredData ?:Array < any > , currentPage ?:number ) {
118125 this . TableRows = new Array < any > ( ) ;
119126 this . contextMenuData = [ ] ;
120- if ( ! ( this . rowData && this . rowData . length ) ) {
121- this . rowData = [ ] ;
127+ if ( ! ( this . _rowData && this . _rowData . length ) ) {
128+ this . _rowData = [ ] ;
122129 }
123- else if ( this . columnDefs . length !== Object . keys ( this . rowData [ 0 ] ) . length ) {
130+ else if ( this . columnDefs . length !== Object . keys ( this . _rowData [ 0 ] ) . length ) {
124131 console . warn ( 'Invalid data: Total Column in def: ' + this . columnDefs . length + 'Total Columns in data:'
125- + Object . keys ( this . rowData [ 0 ] ) . length ) ;
132+ + Object . keys ( this . _rowData [ 0 ] ) . length ) ;
126133 }
127- for ( let j = 0 ; j < this . rowData . length ; ++ j ) {
134+ for ( let j = 0 ; j < this . _rowData . length ; ++ j ) {
128135 const row :TableRow = { data : [ ] , filteredOut : false , filteredOutCommon : false } ;
129136 for ( let i = 0 ; i < this . columnDefs . length ; ++ i ) {
130137 if ( ! ( filteredData && filteredData . length !== 0 && currentPage > 0 ) ) {
131138 this . columnDefs [ i ] . sortState = null ;
132139 this . columnDefs [ i ] . showFilter = false ;
133140 }
134141 row . cellRender = this . cellRenderer ;
135- row . data . push ( this . rowData [ j ] [ this . columnDefs [ i ] . field ] ) ;
142+ row . data . push ( this . _rowData [ j ] [ this . columnDefs [ i ] . field ] ) ;
136143 if ( this . rowSelection ) {
137144 row . rowSelect = false ;
138145 }
@@ -343,8 +350,8 @@ export class DataTableComponent implements OnInit {
343350 this . CurrentPage ++ ;
344351 this . FromRecord += this . pageSize ;
345352 this . ToRecord += this . pageSize ;
346- if ( this . ToRecord > this . rowData . length ) {
347- this . ToRecord = this . rowData . length ;
353+ if ( this . ToRecord > this . _rowData . length ) {
354+ this . ToRecord = this . _rowData . length ;
348355 }
349356 this . setPagedRow ( this . CurrentPage ) ;
350357 }
@@ -693,12 +700,12 @@ export class DataTableComponent implements OnInit {
693700 for ( let i = 0 ; i < data . length ; ++ i ) {
694701 if ( data [ i ] && data [ i ] . length ) {
695702 if ( this . TableRows [ i ] . rowSelect )
696- this . rowData [ i ] = undefined ;
703+ this . _rowData [ i ] = undefined ;
697704 }
698705 }
699- for ( let j = 0 ; j < this . rowData . length ; ++ j ) {
700- if ( ! this . rowData [ j ] ) {
701- this . rowData . splice ( j , 1 ) ;
706+ for ( let j = 0 ; j < this . _rowData . length ; ++ j ) {
707+ if ( ! this . _rowData [ j ] ) {
708+ this . _rowData . splice ( j , 1 ) ;
702709 j -- ;
703710 }
704711 }
@@ -782,31 +789,33 @@ export class DataTableComponent implements OnInit {
782789 }
783790
784791 onRowSizeChange ( $event , value ) {
785- this . pageSize = ( parseInt ( value ) > this . rowData . length ) ? this . rowData . length : this . rowSizes [ 0 ] ;
792+ this . pageSize = ( parseInt ( value ) > this . _rowData . length ) ? this . _rowData . length : this . rowSizes [ 0 ] ;
786793 this . tableDraw ( ) ;
787794 }
788795
789796 private tableDraw ( ) {
790- this . FilterRowCount = this . rowData . length ;
791- this . TotalRows = this . rowData . length ;
797+ this . FilterRowCount = this . _rowData . length ;
798+ this . TotalRows = this . _rowData . length ;
792799 this . FilterData = new Array < FilterOptions > ( this . columnDefs . length ) ;
793800 this . createTableData1 ( ) ;
794- this . TotalPages = Math . ceil ( this . rowData . length / this . pageSize ) ;
801+ this . TotalPages = Math . ceil ( this . _rowData . length / this . pageSize ) ;
795802 this . ToRecord = this . pageSize ;
796803
797804 }
798805
799806 constructor ( private clipboardService :ClipboardService , private filterService :FilterService , private dataTableService :DataTableUtilsService , private ref :ChangeDetectorRef ) {
800807 }
801808
802- ngOnInit ( ) {
809+ private init ( ) {
803810 if ( ! this . theme ) {
804811 this . theme = "standard" ;
805812 }
806-
807813 this . dragTheme = this . theme + '-drag' ;
808- this . pageSize = ( this . rowSizes [ 0 ] > this . rowData . length ) ? this . rowData . length : this . rowSizes [ 0 ] ;
814+ this . pageSize = ( this . rowSizes [ 0 ] > this . _rowData . length ) ? this . _rowData . length : this . rowSizes [ 0 ] ;
809815 this . tableDraw ( ) ;
816+ }
817+ ngOnInit ( ) {
818+ this . init ( ) ;
810819 this . clipboardService . getPasteEvent ( ) . subscribe ( data => this . pasteData ( data ) ) ;
811820 this . dataTableService . getOnDeleteEvent ( ) . subscribe ( data => this . deleteData ( data ) ) ;
812821 }
0 commit comments