1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "fnHeaderCallback" );
4 $(document).ready( function () {
5 /* Check the default */
6 var oTable = $('#example').dataTable( {
7 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
10 { "mData": "browser" },
11 { "mData": "platform" },
12 { "mData": "version" },
16 var oSettings = oTable.fnSettings();
20 "Default should be null",
22 function () { return oSettings.fnHeaderCallback == null; }
27 "Five arguments passed",
33 $('#example').dataTable( {
34 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
36 { "mData": "engine", "aTargets": [0] },
37 { "mData": "browser", "aTargets": [1] },
38 { "mData": "platform", "aTargets": [2] },
39 { "mData": "version", "aTargets": [3] },
40 { "mData": "grade", "aTargets": [4] }
42 "fnHeaderCallback": function ( ) {
43 mPass = arguments.length;
45 "fnInitComplete": function () {
50 function () { return mPass == 5 && bInit; }
54 /* The header callback is called once for the init and then when the data is added */
56 "fnHeaderCallback called once per draw",
62 $('#example').dataTable( {
63 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
65 { "mData": "engine", "aTargets": [0] },
66 { "mData": "browser", "aTargets": [1] },
67 { "mData": "platform", "aTargets": [2] },
68 { "mData": "version", "aTargets": [3] },
69 { "mData": "grade", "aTargets": [4] }
71 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
74 "fnInitComplete": function () {
79 function () { return mPass == 2 && bInit; }
83 "fnRowCallback called on paging (i.e. another draw)",
84 function () { $('#example_next').click(); },
85 function () { return mPass == 3; }
90 "fnRowCallback allows us to alter row information",
93 $('#example').dataTable( {
94 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
96 { "mData": "engine", "aTargets": [0] },
97 { "mData": "browser", "aTargets": [1] },
98 { "mData": "platform", "aTargets": [2] },
99 { "mData": "version", "aTargets": [3] },
100 { "mData": "grade", "aTargets": [4] }
102 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
103 nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";
107 function () { return $('#example thead th:eq(0)').html() == "Displaying 10 records"; }
112 "iStart correct on first page",
114 oSession.fnRestore();
117 $('#example').dataTable( {
118 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
120 { "mData": "engine", "aTargets": [0] },
121 { "mData": "browser", "aTargets": [1] },
122 { "mData": "platform", "aTargets": [2] },
123 { "mData": "version", "aTargets": [3] },
124 { "mData": "grade", "aTargets": [4] }
126 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
134 function () { return mPass; }
139 "iStart correct on second page",
141 oSession.fnRestore();
144 $('#example').dataTable( {
145 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
147 { "mData": "engine", "aTargets": [0] },
148 { "mData": "browser", "aTargets": [1] },
149 { "mData": "platform", "aTargets": [2] },
150 { "mData": "version", "aTargets": [3] },
151 { "mData": "grade", "aTargets": [4] }
153 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
159 "fnInitComplete": function () {
160 $('#example_next').click();
164 function () { return mPass; }
169 "iEnd correct on second page",
171 oSession.fnRestore();
174 $('#example').dataTable( {
175 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
177 { "mData": "engine", "aTargets": [0] },
178 { "mData": "browser", "aTargets": [1] },
179 { "mData": "platform", "aTargets": [2] },
180 { "mData": "version", "aTargets": [3] },
181 { "mData": "grade", "aTargets": [4] }
183 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
189 "fnInitComplete": function () {
190 $('#example_next').click();
194 function () { return mPass; }
199 "aiDisplay length is full data when not filtered",
201 oSession.fnRestore();
204 $('#example').dataTable( {
205 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
207 { "mData": "engine", "aTargets": [0] },
208 { "mData": "browser", "aTargets": [1] },
209 { "mData": "platform", "aTargets": [2] },
210 { "mData": "version", "aTargets": [3] },
211 { "mData": "grade", "aTargets": [4] }
213 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
214 if ( aiDisplay.length == 57 )
221 function () { return mPass; }
225 "aiDisplay length is 9 when filtering on 'Mozilla'",
227 oSession.fnRestore();
230 oTable = $('#example').dataTable( {
231 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
233 { "mData": "engine", "aTargets": [0] },
234 { "mData": "browser", "aTargets": [1] },
235 { "mData": "platform", "aTargets": [2] },
236 { "mData": "version", "aTargets": [3] },
237 { "mData": "grade", "aTargets": [4] }
239 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {
240 if ( aiDisplay.length == 9 )
246 oTable.fnFilter( "Mozilla" );
248 function () { return mPass; }