@@ -131,8 +131,10 @@ angular.module('ngCsv.services').
131
131
132
132
infoArray = [ ] ;
133
133
134
- angular . forEach ( row , function ( field , key ) {
135
- this . push ( that . stringifyField ( field , options ) ) ;
134
+ var iterator = ! ! options . columnOrder ? options . columnOrder : row ;
135
+ angular . forEach ( iterator , function ( field , key ) {
136
+ var val = ! ! options . columnOrder ? row [ field ] : field ;
137
+ this . push ( that . stringifyField ( val , options ) ) ;
136
138
} , infoArray ) ;
137
139
138
140
dataString = infoArray . join ( options . fieldSep ? options . fieldSep : "," ) ;
@@ -193,6 +195,7 @@ angular.module('ngCsv.directives').
193
195
data : '&ngCsv' ,
194
196
filename : '@filename' ,
195
197
header : '&csvHeader' ,
198
+ columnOrder : '&csvColumnOrder' ,
196
199
txtDelim : '@textDelimiter' ,
197
200
decimalSep : '@decimalSeparator' ,
198
201
quoteStrings : '@quoteStrings' ,
@@ -230,7 +233,7 @@ angular.module('ngCsv.directives').
230
233
addByteOrderMarker : $scope . addByteOrderMarker
231
234
} ;
232
235
if ( angular . isDefined ( $attrs . csvHeader ) ) options . header = $scope . $eval ( $scope . header ) ;
233
-
236
+ if ( angular . isDefined ( $attrs . csvColumnOrder ) ) options . columnOrder = $scope . $eval ( $scope . columnOrder ) ;
234
237
235
238
options . fieldSep = $scope . fieldSep ? $scope . fieldSep : "," ;
236
239
0 commit comments