diff --git a/build/ng-csv.js b/build/ng-csv.js index 3babc8b..f127d83 100644 --- a/build/ng-csv.js +++ b/build/ng-csv.js @@ -131,8 +131,10 @@ angular.module('ngCsv.services'). infoArray = []; - angular.forEach(row, function (field, key) { - this.push(that.stringifyField(field, options)); + var iterator = !!options.columnOrder ? options.columnOrder : row; + angular.forEach(iterator, function (field, key) { + var val = !!options.columnOrder ? row[field] : field; + this.push(that.stringifyField(val, options)); }, infoArray); dataString = infoArray.join(options.fieldSep ? options.fieldSep : ","); @@ -193,6 +195,7 @@ angular.module('ngCsv.directives'). data: '&ngCsv', filename: '@filename', header: '&csvHeader', + columnOrder: '&csvColumnOrder', txtDelim: '@textDelimiter', decimalSep: '@decimalSeparator', quoteStrings: '@quoteStrings', @@ -230,7 +233,7 @@ angular.module('ngCsv.directives'). addByteOrderMarker: $scope.addByteOrderMarker }; if (angular.isDefined($attrs.csvHeader)) options.header = $scope.$eval($scope.header); - + if (angular.isDefined($attrs.csvColumnOrder)) options.columnOrder = $scope.$eval($scope.columnOrder); options.fieldSep = $scope.fieldSep ? $scope.fieldSep : ","; diff --git a/build/ng-csv.min.js b/build/ng-csv.min.js index 936c1b5..374bfd8 100644 --- a/build/ng-csv.min.js +++ b/build/ng-csv.min.js @@ -1,2 +1,2 @@ -/*! ng-csv 25-04-2015 */ -!function(a){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",["ngCsv.services"]),angular.module("ngCsv.services",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.services","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.services").service("CSV",["$q",function(a){var b="\r\n",c="",d={"\\t":" ","\\b":"\b","\\v":" ","\\f":"\f","\\r":"\r"};this.stringifyField=function(a,b){return"locale"===b.decimalSep&&this.isFloat(a)?a.toLocaleString():"."!==b.decimalSep&&this.isFloat(a)?a.toString().replace(".",b.decimalSep):"string"==typeof a?(a=a.replace(/"/g,'""'),(b.quoteStrings||a.indexOf(",")>-1||a.indexOf("\n")>-1||a.indexOf("\r")>-1)&&(a=b.txtDelim+a+b.txtDelim),a):"boolean"==typeof a?a?"TRUE":"FALSE":a},this.isFloat=function(a){return+a===a&&(!isFinite(a)||Boolean(a%1))},this.stringify=function(d,e){var f=a.defer(),g=this,h="",i="",j=a.when(d).then(function(a){if(angular.isDefined(e.header)&&e.header){var d,j;d=[],angular.forEach(e.header,function(a){this.push(g.stringifyField(a,e))},d),j=d.join(e.fieldSep?e.fieldSep:","),i+=j+b}var k=[];angular.isArray(a)?k=a:angular.isFunction(a)&&(k=a()),angular.forEach(k,function(a,c){var d,f,h=angular.copy(k[c]);f=[],angular.forEach(h,function(a){this.push(g.stringifyField(a,e))},f),d=f.join(e.fieldSep?e.fieldSep:","),i+=c");g.attr("href",a.URL.createObjectURL(d)),g.attr("download",b.getFilename()),g.attr("target","_blank"),e.find("body").append(g),f(function(){g[0].click(),g.remove()},null)}}c.bind("click",function(){b.buildCSV().then(function(){d()}),b.$apply()})}}}])}(window,document); \ No newline at end of file +/*! ng-csv 12-08-2015 */ +!function(a){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",["ngCsv.services"]),angular.module("ngCsv.services",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.services","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.services").service("CSV",["$q",function(a){var b="\r\n",c="",d={"\\t":" ","\\b":"\b","\\v":" ","\\f":"\f","\\r":"\r"};this.stringifyField=function(a,b){return"locale"===b.decimalSep&&this.isFloat(a)?a.toLocaleString():"."!==b.decimalSep&&this.isFloat(a)?a.toString().replace(".",b.decimalSep):"string"==typeof a?(a=a.replace(/"/g,'""'),(b.quoteStrings||a.indexOf(",")>-1||a.indexOf("\n")>-1||a.indexOf("\r")>-1)&&(a=b.txtDelim+a+b.txtDelim),a):"boolean"==typeof a?a?"TRUE":"FALSE":a},this.isFloat=function(a){return+a===a&&(!isFinite(a)||Boolean(a%1))},this.stringify=function(d,e){var f=a.defer(),g=this,h="",i="",j=a.when(d).then(function(a){if(angular.isDefined(e.header)&&e.header){var d,j;d=[],angular.forEach(e.header,function(a){this.push(g.stringifyField(a,e))},d),j=d.join(e.fieldSep?e.fieldSep:","),i+=j+b}var k=[];angular.isArray(a)?k=a:angular.isFunction(a)&&(k=a()),angular.forEach(k,function(a,c){var d,f,h=angular.copy(k[c]);f=[];var j=e.columnOrder?e.columnOrder:h;angular.forEach(j,function(a){var b=e.columnOrder?h[a]:a;this.push(g.stringifyField(b,e))},f),d=f.join(e.fieldSep?e.fieldSep:","),i+=c");g.attr("href",a.URL.createObjectURL(d)),g.attr("download",b.getFilename()),g.attr("target","_blank"),e.find("body").append(g),f(function(){g[0].click(),g.remove()},null)}}c.bind("click",function(){b.buildCSV().then(function(){d()}),b.$apply()})}}}])}(window,document); \ No newline at end of file diff --git a/package.json b/package.json index ef78d52..702189a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng-csv", - "version": "0.3.3", + "version": "0.3.4", "main": "build/ng-csv.min.js", "description": "Simple directive that turns arrays and objects into downloadable CSV files", "repository": {