angularjs ng-grid hide column

How to hide column in AngularJs ng grid?

Hi, I am going to share the code sample for "How to hide column in ng grid"? and after hide the column some question keep in mind as given below.

After hiding the your columns, may I get the columns value when I select some row? Answers is Yes!!

Click for live demo 

In AngularJs, we can achieve this using column property visible: false. i.e.

1
2
3
4
5
6
//We can achieve this using the property visible: false. i.e.
 columnDefs: [
        { field: 'UserId', displayName: 'UserId', visible: false },
        { field: 'Name', displayName: 'UserName' },
        { field: 'Qualification', displayName: 'Education' }]
//We can achieve this using the property visible: false. i.e.

 columnDefs: [
        { field: 'UserId', displayName: 'UserId', visible: false },
        { field: 'Name', displayName: 'UserName' },
        { field: 'Qualification', displayName: 'Education' }]
For the complete example code as given below.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//For the complete example code as given  below.
<!DOCTYPE html>
<html ng-app="userApp">
<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <style>
    .gridStyle {
      height: 500px;
    }
  </style>
  <link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
  <script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script>
  <script>
    var app = angular.module("userApp", ['ngGrid']);
    app.controller("MyUserController", function($scope) {
      $scope.users = [{
        UserId: 01,
        Name: "Anil Singh",
        Qualification: "MCA"
      }, {
        UserId: 02,
        Name: "Sunil",
        Qualification: "M.A. PhD"
      }, {
        UserId: 03,
        Name: "Sushil",
        Qualification: "B.Tech"
      }, {
        UserId: 04,
        Name: "Dilip",
        Qualification: "MCA"
      }, {
        UserId: 05,
        Name: "Upendra",
        Qualification: "MBA"
      }, {
        UserId: 06,
        Name: "Reena",
        Qualification: "M.A(English)"
      }];
      $scope.gridOptions = {
        data: 'users',
        multiSelect: true,
        columnDefs: [{
          field: 'UserId',
          displayName: 'UserId',
          visible: false
        }, {
          field: 'Name',
          displayName: 'UserName'
        }, {
          field: 'Qualification',
          displayName: 'Education'
        }]
      };
    });
  </script>
</head>
<body ng-controller="MyUserController">
  <div class="gridStyle" ng-grid="gridOptions"></div>
</body>
</html>
//For the complete example code as given  below.

<!DOCTYPE html>
<html ng-app="userApp">

<head>
  <meta charset="utf-8" />
  <title>AngularJs ng-grid hide column</title>
  <style>
    .gridStyle {
      height: 500px;
    }
  </style>
  <link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
  <script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script>
  <script>
    var app = angular.module("userApp", ['ngGrid']);

    app.controller("MyUserController", function($scope) {

      $scope.users = [{
        UserId: 01,
        Name: "Anil Singh",
        Qualification: "MCA"
      }, {
        UserId: 02,
        Name: "Sunil",
        Qualification: "M.A. PhD"
      }, {
        UserId: 03,
        Name: "Sushil",
        Qualification: "B.Tech"
      }, {
        UserId: 04,
        Name: "Dilip",
        Qualification: "MCA"
      }, {
        UserId: 05,
        Name: "Upendra",
        Qualification: "MBA"
      }, {
        UserId: 06,
        Name: "Reena",
        Qualification: "M.A(English)"
      }];


      $scope.gridOptions = {
        data: 'users',
        multiSelect: true,
        columnDefs: [{
          field: 'UserId',
          displayName: 'UserId',
          visible: false
        }, {
          field: 'Name',
          displayName: 'UserName'
        }, {
          field: 'Qualification',
          displayName: 'Education'
        }]
      };
    });
  </script>
</head>

<body ng-controller="MyUserController">
  <div class="gridStyle" ng-grid="gridOptions"></div>
</body>

</html>
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^