ng-table-export icon indicating copy to clipboard operation
ng-table-export copied to clipboard

Export without pagination

Open cboden opened this issue 10 years ago • 22 comments

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.

cboden avatar May 12 '14 13:05 cboden

+1 for this

andrewboni avatar May 23 '14 18:05 andrewboni

+1.

fizerkhan avatar May 26 '14 09:05 fizerkhan

I also +1 one this!

ansofi avatar Jul 03 '14 08:07 ansofi

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.

davisford avatar Jul 12 '14 04:07 davisford

+1 !!!

Thanks!

ghost avatar Jul 25 '14 04:07 ghost

+1

brianglick avatar Jul 26 '14 17:07 brianglick

+1

elebescond avatar Jul 30 '14 12:07 elebescond

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.

davisford avatar Aug 09 '14 04:08 davisford

+1

koju avatar Nov 16 '14 07:11 koju

+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

abhisheksimion avatar Dec 02 '14 04:12 abhisheksimion

+1

martinspielmann avatar Jan 13 '15 13:01 martinspielmann

@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.

davisford avatar Jan 14 '15 15:01 davisford

This problem can be solved from (at least) two ways:

  1. 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;
  2. 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.

thiagodp avatar Apr 16 '15 22:04 thiagodp

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.

davisford avatar Apr 17 '15 00:04 davisford

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.

thiagodp avatar Apr 17 '15 03:04 thiagodp

Which problem with UTF?

davisford avatar Apr 22 '15 19:04 davisford

https://github.com/esvit/ng-table-export/issues/16 (please see my comment)

thiagodp avatar Apr 22 '15 19:04 thiagodp

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 ?

zejli avatar May 28 '15 07:05 zejli

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 avatar Jul 25 '15 22:07 arseneoaa

@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

populationtwo avatar Oct 19 '15 16:10 populationtwo

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/

antusith avatar Jan 02 '17 16:01 antusith

@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();

saniddha avatar Apr 07 '17 06:04 saniddha