[转]ng-grid

本文转自:http://angular-ui.github.io/ui-grid/

Getting Started

Steps for getting started (example on right):

    1. Add references to jQuery and AngularJS.
    2. Add references to ngGrid's javascript and css files.
    3. Where you declare your app module, add ngGrid: angular.module('myApp',['ngGrid']); If you use angular seed, it is in your app.js file.
    4. In your html file within the controller where you plan to use ng-grid, add: <div class="gridStyle" ng-grid="gridOptions"></div> gridOptions is the variable we are going to bind to where we will initialize our grid options.
    5. We are going to define a basic style for our grid in style.css:
      .gridStyle {
          border: 1px solid rgb(212,212,212); width: 400px; height: 300px }
    6. In your javascript file within the controller where you plan to use ng-grid, lets add data that our grid will use:
$scope.myData = [{name: "Moroni", age: 50}, {name: "Tiancum", age: 43}, {name: "Jacob", age: 27}, {name: "Nephi", age: 29}, {name: "Enos", age: 34}];
  1. Now initialize your grid options under the same controller as data: $scope.gridOptions = { data: 'myData' };
  2. Below is the outcome of the grid using the example on the right:
Drag a column header here and drop it to group by that column.
  •         
 
name
 
 
 
 
 
 
age
 
 
 
 
 
 
    
Choose Columns:        
  •                  name 0                     
  • age 0                     
 
Moroni
 
50
 
Tiancum
 
43
 
Jacob
 
27
 
Nephi
 
29
 
Enos
 
34
Total Items: 5(Showing Items: 5)        
Selected Items: 0        
Page Size:            2505001000                     
 
            
 
                          / 1            
 
            
 
        

HTML:

  1. <html ng-app="myApp">
  2. <head lang="en">
  3. <meta charset="utf-8">
  4. <title>Getting Started With ngGrid Example</title>
  5. <link rel="stylesheet" type="text/css" href="ng-grid.css" />
  6. <link rel="stylesheet" type="text/css" href="style.css" />
  7. <script type="text/javascript" src="jquery-1.8.2.js"></script>
  8. <script type="text/javascript" src="angular.js"></script>
  9. <script type="text/javascript" src="ng-grid-1.3.2.js"></script>
  10. <script type="text/javascript" src="main.js"></script>
  11. </head>
  12. <body ng-controller="MyCtrl">
  13. <div class="gridStyle" ng-grid="gridOptions">
  14. </div>
  15. </body>
  16. </html>

CSS:

  1. /*style.css*/
  2. .gridStyle {
  3. border: 1px solid rgb(212,212,212);
  4. width: 400px;
  5. height: 300px
  6. }

Javascript:

  1. // main.js
  2. var app = angular.module('myApp', ['ngGrid']);
  3. app.controller('MyCtrl', function($scope) {
  4. $scope.myData = [{name: "Moroni", age: 50},
  5. {name: "Tiancum", age: 43},
  6. {name: "Jacob", age: 27},
  7. {name: "Nephi", age: 29},
  8. {name: "Enos", age: 34}];
  9. $scope.gridOptions = { data: 'myData' };
  10. });

View the plunker here.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值