forked from l-lin/angular-datatables
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularWayWithOptions.html
More file actions
119 lines (118 loc) · 4.22 KB
/
angularWayWithOptions.html
File metadata and controls
119 lines (118 loc) · 4.22 KB
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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<article class="main-content">
<header class="article-header">
<h1><i class="fa fa-play"></i> The Angular way with options</h1>
</header>
<section class="article-content">
<p>
You can also provide datatable options and datatable column options with the directive
<code>dt-options</code>:
</p>
<p>
<strong>Note:</strong>
</p>
<ul>
<li>
The options do not override what you define in your template. It will just append its properties.
</li>
<li class="text-danger">
When using the angular way, you CANNOT use the <code>dt-column</code> directive. Indeed,
the module will render the datatable after the promise is resolved. So for DataTables, it's like rendering a static table.
If you need to provide some options to your column, your must provide the <code>dt-column-defs</code> directive (which corresponds
to the <a href="https://datatables.net/reference/option/columnDefs">DataTables columnDefs</a>).
</li>
</ul>
</section>
<section class="showcase">
<tabset>
<tab heading="Preview">
<article class="preview">
<div ng-controller="AngularWayWithOptionsCtrl as showCase">
<table datatable="ng" dt-options="showCase.dtOptions" dt-column-defs="showCase.dtColumnDefs" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in showCase.persons">
<td>{{ person.id }}</td>
<td>{{ person.firstName }}</td>
<td>{{ person.lastName }}</td>
</tr>
</tbody>
</table>
</div>
</article>
</tab>
<tab heading="HTML">
<div hljs>
<div ng-controller="AngularWayWithOptionsCtrl as showCase">
<table datatable="ng" dt-options="showCase.dtOptions" dt-column-defs="showCase.dtColumnDefs" class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in showCase.persons">
<td>{{ person.id }}</td>
<td>{{ person.firstName }}</td>
<td>{{ person.lastName }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</tab>
<tab heading="JS">
<div hljs language="js">
angular.module('showcase.angularWay.withOptions', ['datatables', 'ngResource'])
.controller('AngularWayWithOptionsCtrl', AngularWayWithOptionsCtrl);
function AngularWayWithOptionsCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder) {
var vm = this;
vm.persons = [];
vm.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2);
vm.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0),
DTColumnDefBuilder.newColumnDef(1).notVisible(),
DTColumnDefBuilder.newColumnDef(2).notSortable()
];
$resource('data.json').query().$promise.then(function(persons) {
vm.persons = persons;
});
}
</div>
</tab>
<tab heading="Example data">
<p class="example-data">
<a target="_blank" href="/angular-datatables/data.json" tooltip="data.json">data.json <i class="fa fa-external-link"></i></a>
</p>
<div hljs language="json">
[{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}, {
"id": 870,
"firstName": "Foo",
"lastName": "Whateveryournameis"
}, {
"id": 590,
"firstName": "Toto",
"lastName": "Titi"
}, {
"id": 803,
"firstName": "Luke",
"lastName": "Kyle"
},
...
]
</div>
</tab>
</tabset>
</section>
</article>