2017-04-18 32 views
0

我希望表格內容在單元格中右對齊。我在AngularJS中使用pdfmake導出數據。UI Grid AngularJS:單元格過濾器重新對齊表格數據

當我將此過濾器應用於表格數據時,它左對齊表格數據。 這裏是過濾器:

app.filter('rentalFilter', function() { 
    return function (value, scope) { 
    // Only perform logic if the value is actually defined 
    if(typeof value != 'undefined') { 
     if(value == null || value == "") 
      value = 0; 
     value = value.toFixed(2); 
     if(value >= 0) { 
      var parts=value.toString().split("."); 
      return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : ""); 
     } 
     else { 
      value = value * -1.00; 
      value = value.toFixed(2); 
      var parts=value.toString().split("."); 
      return "-" + parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : ""); 
     } 
    } 
    }; 
}); 

沒有這個過濾器,exporterPdfAlign: 'right'對齊每列中的所有內容。

{ 
     name : 'mondayNet', 
     displayName : 'Net', 
     category : "MONDAY", 
     exporterPdfAlign: 'right', 
     width : '14%', 
     cellTemplate : 'app/views/common/templates/cell/pos-neg-cell-template.html', 
     footerCellTemplate : '<div class="ui-grid-cell-contents text-center" ng-class="{positive : col.getAggregationValue() > 0, negative : col.getAggregationValue() < 1}">{{col.getAggregationValue() | number : 2}}</div>', 
     aggregationType : uiGridConstants.aggregationTypes.sum, 
     enableColumnMenu : false 
    }, 

如何在濾鏡中應用正確的對齊方式?由於

回答

0

$scope.export() 

這正是出口的所有數據作爲一個PDF,我補充這一點,右對齊所有各列下的數據

var alignRight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; 
     angular.forEach(content.content[0].table.body, function(row, rowIndex) { 
     if (rowIndex !== 0) { 
      angular.forEach(row, function(column, columnIndex) { 

       if (alignRight.indexOf(columnIndex) !== -1) { 

        content.content[0].table.body[rowIndex][columnIndex] = { 
          text: content.content[0].table.body[rowIndex][columnIndex], 
          alignment: 'right' 
        }; 
       } 
       }); 
     } 
     });