在angular-grid中为ng-grid显示NULL

时间:2013-11-02 17:26:41

标签: angularjs ng-grid

ngGrid根据列类型将我的NULL单元格转换为0或空字符串(“”)。 我需要将其显示为“NULL”。什么是有效方式才能做到这一点?网格中可能会显示10,000多行数据。

Simple Plunker显示不受欢迎的行为: http://plnkr.co/edit/MwAotQ?p=preview

(注意0,“”或$ 0.00而不是NULL)。

谢谢!

- >> Josh<< -

1 个答案:

答案 0 :(得分:5)

创建扩展原始过滤器的自定义过滤器。以下是如何为日期列执行此操作:

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.gridOptions = {
        data: 'myData',
        columnDefs: [{ field: "name", width: 120 },
                    { field: "age", width: 120, cellFilter: 'number' },
                    { field: "birthday", width: 120, cellFilter: 'nullDateFilter' },
                    { field: "salary", width: 120, cellFilter: 'currency'  }]
    };
    $scope.myData = [{ name: "Moroni", age: 50, birthday: "Oct 28, 1970", salary: 60000 },
                    { name: "Tiancum", age: 43, birthday: "Feb 12, 1985", salary: 70000 },
                    { name: "Jacob", age: 27, birthday: "Aug 23, 1983", salary: 50000 },
                    { name: null, age: null, birthday: null, salary: null },
                    { name: "Enos", age: 34, birthday: "Aug 3, 2008", salary: 30000 }];
});

app.filter('nullDateFilter', function($filter) {
  return function(input) {
    var originalFilter = $filter('date');
    return input == null ? 'null' : originalFilter(input);
  };
});