@@ -7,13 +7,40 @@ <h1><i class="fa fa-play"></i> The Angular way with options</h1>
7
7
You can also provide datatable options and datatable column options with the directive
8
8
< code > dt-options</ code > :
9
9
</ p >
10
+ < p >
11
+ < strong > Note:</ strong >
12
+ </ p >
13
+ < ul >
14
+ < li >
15
+ The options do not override what you define in your template. It will just append its properties.
16
+ </ li >
17
+ < li >
18
+ If you use the Angular way of rendering the table along with the Ajax or the promise solution, the latter
19
+ will be display.
20
+ </ li >
21
+ < li >
22
+ The Angular way is less efficient than fetching the data with the Ajax/promise solutions. The lack of
23
+ performance is due to the fact that Angular add the 2 way databinding to the data, which the ajax/promise solutions
24
+ does not. However, you can use Angular directive (< code > ng-click</ code > , < code > ng-controller</ code > ...) in there!
25
+ </ li >
26
+ < li >
27
+ Don't forget to set the properties < code > ng</ code > in the directive < code > datatable</ code > and the < code > dt-rows</ code >
28
+ in order to tell the directive to use the Angular way!
29
+ </ li >
30
+ < li class ="text-danger ">
31
+ < i class ="fa fa-warning "> </ i > When using the angular way, you CANNOT use the < code > dt-column</ code > directive. Indeed,
32
+ the module will render the datatable after the promise is resolved. So for DataTables, it's like rendering a static table.
33
+ If you need to provide some options to your columnn, your must provide the < code > dt-column-defs</ code > directive (which corresponds
34
+ to the < a href ="https://datatables.net/reference/option/columnDefs "> DataTables columnDefs</ a > ).
35
+ </ li >
36
+ </ ul >
10
37
</ section >
11
38
< section class ="showcase ">
12
39
< tabset >
13
40
< tab heading ="Preview ">
14
41
< article class ="preview ">
15
42
< div ng-controller ="angularWayWithOptionsCtrl ">
16
- < table datatable ="ng " dt-options ="dtOptions " dt-columns =" dtColumns " class ="row-border hover ">
43
+ < table datatable ="ng " dt-options ="dtOptions " dt-column-defs =" dtColumnDefs " class ="row-border hover ">
17
44
< thead >
18
45
< tr >
19
46
< th > ID</ th >
@@ -35,7 +62,7 @@ <h1><i class="fa fa-play"></i> The Angular way with options</h1>
35
62
< tab heading ="HTML ">
36
63
< div hljs >
37
64
< div ng-controller ="angularWayWithOptionsCtrl ">
38
- < table datatable ="ng " dt-options ="dtOptions " dt-columns =" dtColumns " class ="row-border hover ">
65
+ < table datatable ="ng " dt-options ="dtOptions " dt-column-defs =" dtColumnDefs " class ="row-border hover ">
39
66
< thead >
40
67
< tr >
41
68
< th > ID</ th >
@@ -57,36 +84,17 @@ <h1><i class="fa fa-play"></i> The Angular way with options</h1>
57
84
< tab heading ="JS ">
58
85
< div hljs language ="js ">
59
86
angular.module('datatablesSampleApp', ['ngResource', 'datatables'])
60
- .controller('angularWayWithOptionsCtrl', function ($scope, $resource, DTOptionsBuilder) {
87
+ .controller('angularWayWithOptionsCtrl', function ($scope, $resource, DTOptionsBuilder, DTColumnDefBuilder ) {
61
88
$scope.persons = $resource('data.json').query();
62
89
$scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers').withDisplayLength(2);
90
+ $scope.dtColumnDefs = [
91
+ DTColumnDefBuilder.newColumnDef(0),
92
+ DTColumnDefBuilder.newColumnDef(1).notVisible(),
93
+ DTColumnDefBuilder.newColumnDef(2).notSortable()
94
+ ];
63
95
});
64
96
</ div >
65
97
</ tab >
66
98
</ tabset >
67
99
</ section >
68
-
69
- < section class ="article-content ">
70
- < p >
71
- < strong > Note:</ strong >
72
- </ p >
73
- < ul >
74
- < li >
75
- The options do not override what you define in your template. It will just append its properties.
76
- </ li >
77
- < li >
78
- If you use the Angular way of rendering the table along with the Ajax or the promise solution, the latter
79
- will be display.
80
- </ li >
81
- < li >
82
- The Angular way is less efficient than fetching the data with the Ajax/promise solutions. The lack of
83
- performance is due to the fact that Angular add the 2 way databinding to the data, which the ajax/promise solutions
84
- does not. However, you can use Angular directive (< code > ng-click</ code > , < code > ng-controller</ code > ...) in there!
85
- </ li >
86
- < li >
87
- Don't forget to set the properties < code > ng</ code > in the directive < code > datatable</ code > in order to tell the directive to use
88
- the Angular way!
89
- </ li >
90
- </ ul >
91
- </ section >
92
100
</ article >
0 commit comments