Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions build/ng-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ angular.module('ngCsv.services').
var labelArray, labelString;

labelArray = [];
angular.forEach(arrData[0], function(value, label) {
this.push(that.stringifyField(label, options));

var iterator = !!options.columnOrder ? options.columnOrder : arrData[0];
angular.forEach(iterator, function(value, label) {
var val = !!options.columnOrder ? value : label;
this.push(that.stringifyField(val, options));
}, labelArray);
labelString = labelArray.join(options.fieldSep ? options.fieldSep : ",");
csvContent += labelString + EOL;
Expand Down Expand Up @@ -221,7 +224,8 @@ angular.module('ngCsv.directives').
addByteOrderMarker: "@addBom",
ngClick: '&',
charset: '@charset',
label: '&csvLabel'
label: '&csvLabel',
title: '@csvTitle'
},
controller: [
'$scope',
Expand Down Expand Up @@ -285,7 +289,7 @@ angular.module('ngCsv.directives').
link: function (scope, element, attrs) {
function doClick() {
var charset = scope.charset || "utf-8";
var blob = new Blob([scope.csv], {
var blob = new Blob([scope.title ? scope.title + '\n' : '', scope.csv], {
type: "text/csv;charset="+ charset + ";"
});

Expand Down
4 changes: 2 additions & 2 deletions build/ng-csv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ <h1>ngCsv <small>example</small></h1>
>Export to CSV</button>

<button class="btn btn-default"
ng-csv="getArray" csv-header="getHeader()" filename="{{ filename }}" field-separator="{{separator}}" decimal-separator="{{decimalSeparator}}"
ng-csv="getArray" filename="{{ filename }}.csv" field-separator="{{separator}}" decimal-separator="{{decimalSeparator}}" csv-title="This is the title."
>Export to CSV with title</button>

<button class="btn btn-default"
ng-csv="getArray" csv-header="getHeader()" filename="{{ filename }}.csv" field-separator="{{separator}}" decimal-separator="{{decimalSeparator}}"
>Export to CSV with header</button>
<button class="btn btn-default"
ng-csv="getArray" csv-header="getHeader()" filename="{{ filename }}.csv" field-separator="{{separator}}" decimal-separator="{{decimalSeparator}}" csv-title="This is the title."
>Export to CSV with header and title </button>

<button class="btn btn-default"
ng-csv="getArray" csv-label="true" filename="{{ filename }}" field-separator="{{separator}}" decimal-separator="{{decimalSeparator}}"
Expand Down
5 changes: 3 additions & 2 deletions src/ng-csv/directives/ng-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ angular.module('ngCsv.directives').
addByteOrderMarker: "@addBom",
ngClick: '&',
charset: '@charset',
label: '&csvLabel'
label: '&csvLabel',
title: '@csvTitle'
},
controller: [
'$scope',
Expand Down Expand Up @@ -85,7 +86,7 @@ angular.module('ngCsv.directives').
link: function (scope, element, attrs) {
function doClick() {
var charset = scope.charset || "utf-8";
var blob = new Blob([scope.csv], {
var blob = new Blob([scope.title ? scope.title + '\n' : '', scope.csv], {
type: "text/csv;charset="+ charset + ";"
});

Expand Down