Skip to content

Commit

Permalink
remove event cancellation (unnecessary); allow delimiter through attr…
Browse files Browse the repository at this point in the history
…ibute; fix "$digest already in progress" error with some outside angular controls like angular-ui dropdown directive
  • Loading branch information
Davis Ford committed Aug 10, 2014
1 parent 6fbbcc3 commit 78c91a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ng-table-export.js

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

2 changes: 1 addition & 1 deletion ng-table-export.map

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

20 changes: 12 additions & 8 deletions ng-table-export.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ angular.module('ngTableExport', [])

var data = '';

// allow pass in of delimiter via directive attrs
if (attrs.delimiter) { delimiter = attrs.delimiter; }

function stringify(str) {
return '"' +
str.replace(/^\s\s*/, '').replace(/\s*\s$/, '') // trim spaces
Expand Down Expand Up @@ -67,20 +70,22 @@ angular.module('ngTableExport', [])
link.href = dataUri;
link.download = filename;
link.target = '_blank';
// must append to body for firefox; chrome & safari don't mind
document.body.appendChild(link);
link.click();
// destroy
document.body.removeChild(link);
// needs to get wrapped to play nicely with angular $digest
// else may cause '$digest already in progress' errors with other angular controls (e.g. angular-ui dropdown)
$timeout(function () {
// must append to body for firefox; chrome & safari don't mind
document.body.appendChild(link);
link.click();
// destroy
document.body.removeChild(link);
}, 0, false);
}

var csv = {
/**
* Generate data URI from table data
*/
generate: function(event, filename) {
event.stopPropagation();
event.preventDefault();

var table = scope.$parent.tableParams,
settings = table.settings(),
Expand Down Expand Up @@ -113,7 +118,6 @@ angular.module('ngTableExport', [])
parseTable();
download(header + encodeURIComponent(data), filename);
}
return false;
}
};

Expand Down
20 changes: 12 additions & 8 deletions src/scripts/00-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ angular.module('ngTableExport', [])

var data = '';

// allow pass in of delimiter via directive attrs
if (attrs.delimiter) { delimiter = attrs.delimiter; }

function stringify(str) {
return '"' +
str.replace(/^\s\s*/, '').replace(/\s*\s$/, '') // trim spaces
Expand Down Expand Up @@ -67,20 +70,22 @@ angular.module('ngTableExport', [])
link.href = dataUri;
link.download = filename;
link.target = '_blank';
// must append to body for firefox; chrome & safari don't mind
document.body.appendChild(link);
link.click();
// destroy
document.body.removeChild(link);
// needs to get wrapped to play nicely with angular $digest
// else may cause '$digest already in progress' errors with other angular controls (e.g. angular-ui dropdown)
$timeout(function () {
// must append to body for firefox; chrome & safari don't mind
document.body.appendChild(link);
link.click();
// destroy
document.body.removeChild(link);
}, 0, false);
}

var csv = {
/**
* Generate data URI from table data
*/
generate: function(event, filename) {
event.stopPropagation();
event.preventDefault();

var table = scope.$parent.tableParams,
settings = table.settings(),
Expand Down Expand Up @@ -113,7 +118,6 @@ angular.module('ngTableExport', [])
parseTable();
download(header + encodeURIComponent(data), filename);
}
return false;
}
};

Expand Down

0 comments on commit 78c91a3

Please sign in to comment.