annotate DataTables-1.9.4/media/unit_testing/tests_onhold/6_delayed_rendering/fnHeaderCallback.js @ 9:7300ed4c1481 draft default tip

Uploaded
author saskia-hiltemann
date Mon, 04 Sep 2017 10:49:00 -0400
parents ac5f9272033b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 // DATA_TEMPLATE: empty_table
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 oTest.fnStart( "fnHeaderCallback" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 $(document).ready( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 /* Check the default */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 var oTable = $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 "bDeferRender": true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 var oSettings = oTable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 var mPass, bInit;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 "Default should be null",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 function () { return oSettings.fnHeaderCallback == null; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 "Five arguments passed",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 mPass = -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 bInit = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 "fnHeaderCallback": function ( ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 mPass = arguments.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 "fnInitComplete": function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 bInit = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 function () { return mPass == 5 && bInit; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 /* The header callback is called once for the init and then when the data is added */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 "fnHeaderCallback called once per draw",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 mPass = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 bInit = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 mPass++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 "fnInitComplete": function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 bInit = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 function () { return mPass == 2 && bInit; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 "fnRowCallback called on paging (i.e. another draw)",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 function () { $('#example_next').click(); },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 function () { return mPass == 3; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 "fnRowCallback allows us to alter row information",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 function () { return $('#example thead th:eq(0)').html() == "Displaying 10 records"; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 "iStart correct on first page",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 if ( iStart != 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 "iStart correct on second page",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 if ( iStart == 10 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 "fnInitComplete": function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 $('#example_next').click();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 "iEnd correct on second page",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 if ( iEnd == 20 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 "fnInitComplete": function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 $('#example_next').click();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 "aiDisplay length is full data when not filtered",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 if ( aiDisplay.length == 57 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 "aiDisplay length is 9 when filtering on 'Mozilla'",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 oTable = $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 if ( aiDisplay.length == 9 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 oTable.fnFilter( "Mozilla" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 oTest.fnComplete();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 } );