2

ngGrid is converting my NULL cells to 0 or an empty string ("") based on the column type. I need this displayed as 'NULL' instead. What is an efficient way to do this? There could be 10,000+ rows of data displayed in the Grid.

Simple Plunker displaying undesired behaviour: http://plnkr.co/edit/MwAotQ?p=preview

(notice 0, "", or $0.00 instead of NULL).

Thanks!

->> Josh <<-

1 Answer 1

5

Create a custom filter that extends the original filter. Here is how you would do it for your date column:

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);
  };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.