blsrm / ngTableExcelExport

JavaScript export to Excel or CSV from HTML tables automatically in the browser and also compatible with all browsers
MIT License
9 stars 9 forks source link

How to do it Angular JS way. #1

Open Matias-Barrios opened 7 years ago

Matias-Barrios commented 7 years ago

Hi All,

Im trying to make use of this fantasic tool. But the problem is that my table is a paginated ng-table so only the first displayed table gets downloaded. In order to fix that I created a function that set the items per page to some super high limit (10000 in this case but 99999 would also be good ) so I can download the entire thing. My problem is I dont know how to use it from an Angular function.

Could someone help me on this?

   <button id="exporttocsv"  ng-click="setTable()" > Export!! </button>

   $scope.setTable = function () {
       $scope.tableParams.count(10000);
     return ngTableExcelExport.csv(this, 'main_table', 'Sheet Name Here')
    };

Im new to Angular but I understand my above code will never work, therefore I need your help understanding how to combine this code with Angular. Thanks!

RLTCmpe commented 7 years ago

I am not sure how you have the controller setup or what isn't working but I did it this way.

$scope.setTable = function() { //set count to length of your data $scope.TableParams = new NgTableParams({ count: $scope.maintable.length }, { count: [5, 10, 25], dataset: $scope.maintable)};

//timeout is needed to allow your ng table to render and show all the data. $timeout( function(){ return ngTableExcelExport.csv(this, 'main_table', 'Sheet Name Here') }, 1500 ); //might have to increase the timeout if there is alot of data in the 'main_table'

};