Wijmo Grid 指令
最后一个例子是可编辑的表格指令:
这里展示的图表插件是 Wijmo 前端插件套包中的一款插件 wijgrid 插件:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<wij-griddata="data"allow-editing="true"after-cell-edit="cellEdited(e, args)" ><wij-grid-columnbinding="country" width="100" group="true"></wij-grid-column><wij-grid-columnbinding="product" width="140" ></wij-grid-column><wij-grid-columnbinding="amount" width="100" format="c2" aggregate="sum" ></wij-grid-column></wij-grid> |
"wij-grid" 指令定制表格的属性,"wij-grid-column" 指令定制特性表格列的属性。以上标记定义了一个拥有三列的可编辑表格,分别为:“country”, "product" 和 "amount"。并且,以country列分组并且计算每个分组的合计。
这个指令中最特别的一点是 “wij-grid”和“wij-grid-column”的连接。为了使这个连接起作用,父指令中定义了如下controller:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
app.directive("wijGrid", [ "$rootScope", "wijUtil", function ($rootScope, wijUtil) {return {restrict: "E",replace: true,transclude: true,template: "<table ng-transclude/>",scope: {data: "=", // List of items to bind to.allowEditing: "@", // Whether user can edit the grid.afterCellEdit: "&", // Event that fires after cell edits.allowWrapping: "@", // Whether text should wrap within cells.frozenColumns: "@" // Number of non-scrollable columns},controller: ["$scope", function ($scope) {$scope.columns = [];this.addColumn = function (column) {$scope.columns.push(column);}}],link: function (scope, element, attrs) {// omitted for brevity, see full source here: // http://jsfiddle.net/Wijmo/jmp47/}}}]); |
关于controller ���法使用前文中提到的数组语法声明,在这个例子中,controller定义了addColumn 方法,它将会被"wij-grid-column" 指令调用。父指令会通过特定标记来访问列。
以下是"wij-grid-column" 指令的使用方法:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
app.directive("wijGridColumn", function () {return {require: "^wijGrid",restrict: "E",replace: true,template: "<div></div>",scope: {binding: "@", // Property shown in this column.header: "@", // Column header content.format: "@", // Format used to display numeric values in this column.width: "@", // Column width in pixels.aggregate: "@", // Aggregate to display in group header rows.group: "@", // Whether items should be grouped by the values in this column.groupHeader: "@" // Text to display in the group header rows.},link: function (scope, element, attrs, wijGrid) {wijGrid.addColumn(scope);}}}); |
require 成员用于指定"wij-grid-column" 指令的父级指令"wij-grid"。link 方法接收父指令的引用 (controller) ,同时通过addColumn 方法传递自身的scope 给父指令。scope 包含了表格用于创建列的所有信息。
更多指令
链接为一些AngularJS 指令的在线实例: http://wijmo.gcpowertools.com.cn/demo/AngularExplorer/ ,你可以在例子的基础上进行练习。例子都是严格的安照本文中的描述制作的,所以你可以无障碍学习他们。
 
资源推荐:
1. AngularJS by Google AngularJS主页。
2. AngularJS Directives documentation AngularJS 指令官方帮助文档。
3. AngularJS directives and the computer science of JavaScript 比较实用的AngularJS指令说明文章。
4. Video Tutorial: AngularJS Fundamentals in 60-ish Minutes AngularJS 介绍视频。
5. About those directives AngularJS 研发人员发布的视频教程。
6. Egghead.io AngularJS 使用系列视频教程。
7. Wijmo AngularJS Samples AngularJS 在线实例。
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/102142.htm

