1
1
import {
2
2
Component ,
3
- OnInit ,
3
+ EventEmitter ,
4
+ Input ,
4
5
OnChanges ,
6
+ OnDestroy ,
7
+ OnInit ,
5
8
Output ,
6
- Input ,
7
- EventEmitter ,
8
- Type ,
9
- SimpleChanges ,
10
9
Renderer2 ,
11
- OnDestroy
10
+ SimpleChanges ,
11
+ Type
12
12
} from '@angular/core' ;
13
13
import {
14
14
GtConfig ,
15
15
GtConfigField ,
16
16
GtConfigSetting ,
17
- GtTexts ,
18
- GtInformation ,
17
+ GtEvent ,
19
18
GtExpandedRow ,
20
- GtRow ,
19
+ GtInformation ,
21
20
GtOptions ,
22
- GtRowMeta ,
23
21
GtRenderField ,
24
- GtEvent
22
+ GtRow ,
23
+ GtRowMeta ,
24
+ GtTexts
25
25
} from '..' ;
26
26
import { GtMetaPipe } from '../pipes/gt-meta.pipe' ;
27
27
@@ -84,6 +84,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
84
84
set gtTotals ( value : any ) {
85
85
this . _gtTotals = value ;
86
86
}
87
+
87
88
@Input ( )
88
89
set gtFields ( value : GtConfigField < R , any > [ ] ) {
89
90
this . _gtFields = value ;
@@ -98,6 +99,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
98
99
) ;
99
100
}
100
101
}
102
+
101
103
@Input ( )
102
104
set gtSettings ( value : GtConfigSetting [ ] ) {
103
105
this . _gtSettings = value ;
@@ -139,6 +141,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
139
141
}
140
142
this . restructureSorting ( ) ;
141
143
}
144
+
142
145
@Input ( )
143
146
set gtData ( initialData : Array < any > ) {
144
147
const data = this . _gtOptions . mutateData
@@ -650,6 +653,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
650
653
public deselectAllRows ( ) : void {
651
654
this . _toggleAllRowProperty ( 'isSelected' , false ) ;
652
655
}
656
+
653
657
/**
654
658
* Toggle all rows.
655
659
*/
@@ -1035,6 +1039,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1035
1039
this . _listenForKeydownEvent ( ) ;
1036
1040
}
1037
1041
}
1042
+
1038
1043
/**
1039
1044
* Listen for key down event - listen for key down event during inline edit.
1040
1045
*/
@@ -1055,6 +1060,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1055
1060
}
1056
1061
) ;
1057
1062
}
1063
+
1058
1064
/**
1059
1065
* Inline edit update - accept changes and update row values.
1060
1066
*/
@@ -1077,6 +1083,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1077
1083
// remove listener
1078
1084
this . _stopListeningForKeydownEvent ( ) ;
1079
1085
}
1086
+
1080
1087
/**
1081
1088
* Inline edit cancel - cancel and reset inline edits.
1082
1089
*/
@@ -1104,6 +1111,7 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1104
1111
// remove listener
1105
1112
this . _stopListeningForKeydownEvent ( ) ;
1106
1113
}
1114
+
1107
1115
/**
1108
1116
* Stop listening for key down event - stop listening for key down events passed during inline edit.
1109
1117
*/
@@ -1297,6 +1305,19 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1297
1305
// csv export headers
1298
1306
for ( let i = 0 ; i < this . _gtSettings . length ; i ++ ) {
1299
1307
if ( this . _gtSettings [ i ] . export !== false ) {
1308
+ // get field settings
1309
+ const fieldSetting = this . getProperty (
1310
+ this . _gtFields ,
1311
+ this . _gtSettings [ i ] . objectKey
1312
+ ) ;
1313
+
1314
+ // get export value, if exportHeader string is defined use it otherwise returns name
1315
+ const exportValue : string = fieldSetting . exportHeader
1316
+ ? fieldSetting . exportHeader
1317
+ : fieldSetting . name ;
1318
+
1319
+ csv += this . escapeCSVDelimiter ( exportValue ) ;
1320
+
1300
1321
csv += this . getProperty ( this . _gtFields , this . _gtSettings [ i ] . objectKey )
1301
1322
. name ;
1302
1323
@@ -1318,21 +1339,15 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1318
1339
) ;
1319
1340
1320
1341
// get export value, if export function is defined use it otherwise check for value function and as a last resort export raw data
1321
- let exportValue : string =
1342
+ const exportValue : string =
1322
1343
fieldSetting . export && typeof fieldSetting . export === 'function'
1323
1344
? fieldSetting . export ( row )
1324
1345
: fieldSetting . value && typeof fieldSetting . value === 'function'
1325
1346
? fieldSetting . value ( row )
1326
1347
: row [ this . _gtSettings [ i ] . objectKey ] ;
1327
1348
1328
- // escape export value using double quotes (") if export value contains delimiter
1329
- exportValue =
1330
- typeof exportValue === 'string' &&
1331
- exportValue . indexOf ( this . _gtOptions . csvDelimiter ) !== - 1
1332
- ? '"' + exportValue + '"'
1333
- : exportValue ;
1349
+ csv += this . escapeCSVDelimiter ( exportValue ) ;
1334
1350
1335
- csv += exportValue ;
1336
1351
if ( i < this . _gtSettings . length - 1 ) {
1337
1352
csv += this . _gtOptions . csvDelimiter ;
1338
1353
}
@@ -1437,6 +1452,17 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
1437
1452
}
1438
1453
} ;
1439
1454
1455
+ /**
1456
+ * Escape export value using double quotes (") if export value contains delimiter
1457
+ * @param value Value to be escaped
1458
+ */
1459
+ private escapeCSVDelimiter ( value ) {
1460
+ return typeof value === 'string' &&
1461
+ value . indexOf ( this . _gtOptions . csvDelimiter ) !== - 1
1462
+ ? '"' + value + '"'
1463
+ : value ;
1464
+ }
1465
+
1440
1466
ngOnInit ( ) {
1441
1467
// if number of row to display from start is set to null or 0...
1442
1468
if ( ! this . gtOptions . numberOfRows ) {
0 commit comments