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