sne25088 sne25088 -5 years ago 560
AngularJS Question

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

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?

Answer Source

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download