2

I want to add validation, such that those cells of my grid, which have age more than 40, will show in red color?

     <html ng-app="myApp">  
     <head lang="en">
     <meta charset="utf-8">
     <title>Getting Started With ngGrid Example</title>  
     <link rel="stylesheet" type="text/css" href="ng-grid.css" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script type="text/javascript" src="jquery-1.8.2.js"></script>
    <script type="text/javascript" src="angular.js"></script>
     <script type="text/javascript" src="ng-grid-1.3.2.js"></script>
     <script type="text/javascript">
     var app = angular.module('myApp', ['ngGrid']);
         app.controller('MyCtrl', function($scope) {
                 $scope.myData = [{name: "Moroni", age: 50},
                 {name: "Tiancum", age: 43},
                 {name: "Jacob", age: 27},
                 {name: "Nephi", age: 29},
                 {name: "Enos", age: 34}];
        $scope.gridOptions = { 
           data: 'myData',
       enableCellSelection: true
                         };
            });
          </script>
             </head>
    <body ng-controller="MyCtrl">
       <div class="gridStyle" ng-grid="gridOptions"></div>
    </body>
    </html>

How Can I do that? Please help me?

1
  • Hi **ng-grid is being rewritten as UI Grid, it's in beta! ** Commented Apr 25, 2015 at 5:35

2 Answers 2

2

You can add a cell template to your grid

 $scope.gridOptions = { 
     data: 'myData',
     enableCellSelection: true
     columnDefs: [{cellTemplate: '<div ng-class="{red: row.getProperty(col.field) > 40}"><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}]
};

See the Template Examples section of the docs for more.

Sign up to request clarification or add additional context in comments.

Comments

1

you can use this.

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [{name: "Moroni", age: 50},
                    {name: "Tiancum", age: 43},
                    {name: "Jacob", age: 27},
                    {name: "Nephi", age: 29},
                    {name: "Enos", age: 34}];
    $scope.gridOptions = { 
        data: 'myData',
        columnDefs: [{field: 'name', displayName: 'Name'},
                     {field:'age', displayName:'Age', cellTemplate: '<div ng-class="{red: row.getProperty(col.field) > 40}"><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}]
        };
});

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.