简体   繁体   English

UI Grid AngularJS:单元格过滤器重新对齐表数据

[英]UI Grid AngularJS: Cell Filter realigns the table data

I want the table content to be right aligned in the cell. 我希望表格内容在单元格中正确对齐。 I am exporting the data using pdfmake within AngularJS. 我正在AngularJS中使用pdfmake导出数据。

When I apply this filter to the table data it left aligns the table data. 当我将此过滤器应用于表格数据时,它使表格数据左对齐。 Here is the filter: 这是过滤器:

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] : "");
        }
    }
  };
});

Without this filter, exporterPdfAlign: 'right' aligns all the content within each column. 如果没有此过滤器, 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
    },

How can I apply the right alignment for text within the filter? 如何在过滤器中对文本应用正确的对齐方式? Thanks 谢谢

Within

$scope.export()

which is what exports all the data as a pdf, i added this that right aligns all the data under each column 这就是将所有数据导出为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'
                    };
                }
              });
        }
      });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM