Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export data from Smart Table in AngularJS

In AngularJS project I'm using Smart Table module and asafdav/ng-csv to export data from smart table to CSV.

I successfully export data from smart table to csv, but only from first page. I export data from $scope.displayedCollection variable (the same as in st-table directive). In this variable is exacly the same data as in table, but only from first page. Do you know how can I export whole data (with sorting and filtering from smart table). I think that I should "plug in" to smart table module before splitting data to pages. But how?

like image 474
sne25088 Avatar asked Jan 29 '26 01:01

sne25088


1 Answers

I created my own directive for get access to data from table before pagination:

angular.module('smart-table')
.directive('stFilteredCollection', function () {
    return {
      restrict: 'A',
      require: '^stTable',
      scope: {
        stFilteredCollection: '='
      },
      controller: 'stTableController',
      link: function (scope, element, attr, ctrl) {

        scope.$watch(function () {
          return ctrl.getFilteredCollection();
        }, function (newValue, oldValue) {
          scope.stFilteredCollection = ctrl.getFilteredCollection();
        });
      }
    };
  });

To use it please add st-filtered-collection attribute with name of variable which will be setting to data from table before pagination:

<table st-table="..." st-safe-src="..." st-filtered-collection="filteredCollection">
   ...
</table>

From now in controller you can use $scope.filteredCollection variable.

like image 147
sne25088 Avatar answered Jan 30 '26 15:01

sne25088



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!