CSV

html

 <button type="submit" class="btn btn-success" filename="{{ getFilename() }}" field-separator=";" quote-strings='"' lazy-load="true" ng-csv="download()" csv-header="getHeader()">
 Download
 </button>

controller

$scope.download = function() {
            return ApprovalCMS[$scope.basicSearchFunction()]($scope.query, 0, 9999999, {"update_time": -1}, $scope.searchId).then(function(data){
                var exportData = [];
                 _.forEach(data.products, function(product){
                     exportData.push(
                         {
                             "shop_sku": product.shop_sku,
                             "ean": product.ean,
                             "title": product.title,
                             "failure_reason": _.trim(_.join(_.values(product.failure_reason), ','), ',')
                         });
                 });
                return Promise.resolve(exportData);
            });
        };

        $scope.getHeader = function () {
            return ["Shop sku", "EAN", "Title", "Rejection reason"]
        };

        $scope.getFilename = function () {
            return 'rejectedProducts_' + $filter('date')(new Date(), "yyyyMMddHHmmss") + '.csv'
        };

Last updated