ng-table-export
ng-table-export copied to clipboard
Export without pagination
I'm using ng-table 0.3.1 with ng-table-export master branch. When I export to csv I only get the results of the page and count that has been selected. I would like to download the full result set, not just the current page that is being displayed.
Ideally could the export trigger the ngTableParams.getData function with a parameter indicating it's a csv export. I could then choose to paginate or not.
+1 for this
+1.
I also +1 one this!
I believe this is related to https://github.com/esvit/ng-table/issues/114. The pager + group functionality seems broken in ng-table proper; I think if that issue got fixed, this issue would be resolved.
Sorry, not related. I didn't realize that the way he implemented is he is just scraping the table for the values. I concur -- what @cboden said above, using getData
is the way to go, and seems like it would be simpler.
+1 !!!
Thanks!
+1
+1
I had to solve this. I forked the repo, and rebuilt the plugin -- see the README https://github.com/davisford/ng-table-export
Unfortunately, this was a fairly big re-write of the plugin, so I'm not going to send a PR. I've only been testing it in my own project and it seems to work fairly well. I have a lot of different report style pages with charts and many different tables, and it is working so far. Feel free to try it. If you're using bower, you can just point the dependency in bower.json
to
"ng-table-export": "https://github.com/davisford/ng-table-export.git"
and try it out. The usage has changed slightly, so consult the updated README. There are a few other improvements listed there as well.
Finally, while using getData()
would ultimately seem like the right approach here, I get now why it may not be optimal. My tables have group headers, table headers, footers -- all providing things like summary aggregate values, etc. This stuff doesn't exist in getData()
...so for me, parsing the HTML is actually better because the exported csv matches the table format precisely.
caveat -- works in chrome and firefox. in safari, it opens and displays the csv. have not tested IE b/c we are not targeting it.
Cheers.
+1
+1 @davisford Thanks. I used your plugin. My stackoverflow question here http://stackoverflow.com/questions/27228799/how-to-export-whole-data-from-a-table-in-angularjs-including-all-paginated-data/27241811#27241811
+1
@abhisheksimion thanks -- feel free to send back a pr if you have improvements. FWIW, i have been using my solution in production now for about 6 months with zero issues.
I wrote a similar plugin to export XLS format.
This problem can be solved from (at least) two ways:
- Passing limit = 0 and offset = 0 to the server, for generating the full list (I consider these values to mean "no limit" and "no offset") and then exporting it;
- Configuring the number of items per page equal to a large number (e.g. 999999999). When the user clicks it, the full list is shown and Export will export all the content. The second one can be interesting for the user. He/she can export just a limited set of the data or the full data. The same applies to printing.
hello @thiagodp thanks for the input, and no offense but i think you're a bit late to the party.
solution 1 is a totally different solution unrelated to ng-table-export. this plugin parses the html table in memory and regenerates it as a download link in csv format.
i forked and modified the repo to do something similar to solution 2. i set the # pager rows to Infinity
, parse the results into csv, generate the download link and then set it back to whatever the pager was set to before.
we've been hammering on this in production for nearly a year, and we get a lot of csv and xls exports -- it has worked flawlessly for us. caveat: we don't do millions of rows - that gets to just be infeasible inline in the browser and real client/server paging is called for, but it can deal with several thousand rows without the blink of an eye. of course it depends on your hardware, but with modern 2010's hardware it has not been an issue for us.
Hello @davisford, I don't think I'm late to the party: there are people still using esvit's solution. These can still benefit from my suggestion. Glad to hear your solution has been worked well. I think I will try it. Could you also solve the UTF problem? Thanks.
Which problem with UTF?
https://github.com/esvit/ng-table-export/issues/16 (please see my comment)
Hello every body, I forked the new repo and followed the way to use the export CSV like it is shown in the README.My csv show only the current rows in the page.Not all the pages.am I missing something ?
Hello, If you also find that the logic printing all rows in the table and not just those displayed (by expanding the pagination) doesn't work, it may be because you are not using "tableParams" as your tableParams variable, @davisford has covered that: try adding it as a 3rd argument like:
a(ng-controller='MyCtrl', ng-click='csv.generate($event, filename() + ".csv", $scope.myCustomTableParams)', href='')
@arseneoaa Adding 3rd argument doesn't seem to work on controller as styntax.
<a ng-controller='MyCtrl as mc' ng-click='csv.generate($event, filename() + ".csv", mc.myCustomTableParams)'></a>
Any clue? Thanks
Hello, does anybody could explain how to make it work ? I've written my code like this but nothing is triggered...
https://jsfiddle.net/krptko55/
@davisford
-
define a global variable in ng-table.js like var selectedEntries =''";
-
Then inside the getData function in the ng-table.js insert following line selectedEntries = orderedData;
function getData(data, params) { if (data == null){ return []; }
var options = angular.extend({}, defaultDataOptions, params.settings().dataOptions);
var fData = options.applyFilter ? applyFilter(data, params) : data;
var orderedData = options.applySort ? applySort(fData, params) : fData;
selectedEntries = orderedData;
return options.applyPaging ? applyPaging(orderedData, params) : orderedData;
}
-
Then write a simple function inside the ng-table.js like following this.orderedData = function () { return selectedEntries };
-
Then you can call as following in the controller and get all the filtered entries $scope.self.tableParams.orderedData();