Application of Angular table tool 'ui-grid'

一个新手
Release: 2017-10-02 19:42:36
Original
1859 people have browsed it

HTML: (The code is only used to explain more clearly and does not fully demonstrate)


<!doctype html><html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="/release/ui-grid.js"></script>
    <script src="/release/ui-grid.css"></script>
    <script src="app.js"></script>
  </head>
  <body>
    <p ng-controller="MainCtrl">
      <p id="user-grid" ui-grid="gridOptions" class="user-grid" ui-grid-resize-columns></p></p>
    </p>
  </body></html>
Copy after login

ui-grid-resize-columns: Make the columns change width, like this:

##Jvar app = angular.module('app', ['ngTouch', 'ui.grid ']);


{roleName:&#39;后端&#39;,&#39;roleId&#39;:3}],
             &#39;accountId&#39;:201
Copy after login
{roleName:&#39;后端&#39;,&#39;roleId&#39;:3}],
             &#39;accountId&#39;:201
          }
Copy after login
       ]

}]);
Copy after login
效果如下:
Copy after login

ui-grid使用中文:i18nService.setCurrentLang("zh-cn");
设置ui-grid格式:通过html中的ui-grid=&#39;gridOptions&#39; (gridOptions可以自己定义) 再通过$scope.gridOptions来绑定
在上面的代码中:
enableSorting:定义是否排序
对于列的定义columnDefs中:
field就是表格数据$scope.gridOptions.data中的字段,
displayName就是显示在表格中的显示的列项名,如果没有定义,那么显示的就是field的名称
可以使用,单元格定义的html中如果要绑定函数,并不能像angular常规的来绑定,需要在绑定的函数前加上“grid.appScope”,比如“grid.appScope.func()”
ui-grid如果要将某行的某个数据传入函数中需要使用这样的形式:“row.entity.createTime”,creatTime就是你要传入的参数的名称(对应于“field”)
表格的数据可以通过请求后端接口来获取,赋值给$scope.gridOptions.data,需要注意数据格式是否符合要求,否则就要先处理好。
Copy after login

The above is the detailed content of Application of Angular table tool 'ui-grid'. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template