Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting specific columns #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions src/scripts/00-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ angular.module('ngTableExport', [])
'"';
},
generate: function() {
//this array holds true or false for each header based on
//whether they have the 'no-export' class or not
var exports = [];
data = '';
var rows = element.find('tr');
angular.forEach(rows, function(row, i) {
Expand All @@ -29,13 +32,25 @@ angular.module('ngTableExport', [])
if (tds.length == 0) {
tds = tr.find('td');
}
else {
//go through the headers and check if they have the
//'no-export' class
for(var i = 0; i < tds.length; i++) {
exports[i] = angular.element(tds[i]).hasClass('no-export');
}
}
if (i != 1) {
angular.forEach(tds, function(td, i) {
rowData += csv.stringify(angular.element(td).text()) + ';';
//if the corresponding index in exports[] is false, this
//header does not have the 'no-export' class and is therefore exported
if(exports[i] == false) {
rowData += csv.stringify(angular.element(td).text()) + ';';
}
});
rowData = rowData.slice(0, rowData.length - 1); //remove last semicolon
}
data += rowData + "\n";

});
},
link: function() {
Expand All @@ -45,4 +60,4 @@ angular.module('ngTableExport', [])
$parse(attrs.exportCsv).assign(scope.$parent, csv);
}
};
}]);
}]);