@@ -69,9 +69,9 @@ export class DataTableDirective implements OnDestroy, OnInit {
69
69
this . dtOptions = dtOptions ;
70
70
}
71
71
this . dtInstance = new Promise ( ( resolve , reject ) => {
72
- Promise . resolve ( this . dtOptions ) . then ( dtOptions => {
72
+ Promise . resolve ( this . dtOptions ) . then ( resolvedDTOptions => {
73
73
// validate object
74
- const isTableEmpty = Object . keys ( dtOptions ) . length == 0 && $ ( 'tbody tr' , this . el . nativeElement ) . length == 0 ;
74
+ const isTableEmpty = Object . keys ( resolvedDTOptions ) . length === 0 && $ ( 'tbody tr' , this . el . nativeElement ) . length = == 0 ;
75
75
if ( isTableEmpty ) {
76
76
reject ( 'Both the table and dtOptions cannot be empty' ) ;
77
77
return ;
@@ -81,15 +81,15 @@ export class DataTableDirective implements OnDestroy, OnInit {
81
81
// Assign DT properties here
82
82
let options : ADTSettings = {
83
83
rowCallback : ( row , data , index ) => {
84
- if ( dtOptions . columns ) {
85
- const columns = dtOptions . columns ;
84
+ if ( resolvedDTOptions . columns ) {
85
+ const columns = resolvedDTOptions . columns ;
86
86
// Filter columns with pipe declared
87
87
const colsWithPipe = columns . filter ( x => x . ngPipeInstance && ! x . ngTemplateRef ) ;
88
88
// Iterate
89
89
colsWithPipe . forEach ( el => {
90
90
const pipe = el . ngPipeInstance ;
91
91
// find index of column using `data` attr
92
- const i = columns . findIndex ( e => e . data == el . data ) ;
92
+ const i = columns . findIndex ( e => e . data === el . data ) ;
93
93
// get <td> element which holds data using index
94
94
const rowFromCol = row . childNodes . item ( i ) ;
95
95
// Transform data with Pipe
@@ -104,8 +104,8 @@ export class DataTableDirective implements OnDestroy, OnInit {
104
104
colsWithTemplate . forEach ( el => {
105
105
const { ref, context } = el . ngTemplateRef ;
106
106
// get <td> element which holds data using index
107
- const index = columns . findIndex ( e => e . data == el . data ) ;
108
- const cellFromIndex = row . childNodes . item ( index ) ;
107
+ const i = columns . findIndex ( e => e . data = == el . data ) ;
108
+ const cellFromIndex = row . childNodes . item ( i ) ;
109
109
// render onto DOM
110
110
// finalize context to be sent to user
111
111
const _context = Object . assign ( { } , context , context ?. userData , {
@@ -117,13 +117,13 @@ export class DataTableDirective implements OnDestroy, OnInit {
117
117
}
118
118
119
119
// run user specified row callback if provided.
120
- if ( this . dtOptions . rowCallback ) {
121
- this . dtOptions . rowCallback ( row , data , index ) ;
120
+ if ( resolvedDTOptions . rowCallback ) {
121
+ resolvedDTOptions . rowCallback ( row , data , index ) ;
122
122
}
123
123
}
124
124
} ;
125
125
// merge user's config with ours
126
- options = Object . assign ( { } , dtOptions , options ) ;
126
+ options = Object . assign ( { } , resolvedDTOptions , options ) ;
127
127
this . dt = $ ( this . el . nativeElement ) . DataTable ( options ) ;
128
128
resolve ( this . dt ) ;
129
129
} ) ;
0 commit comments