| 1 |
// DATA_TEMPLATE: dom_data |
| 2 |
oTest.fnStart( "fnFooterCallback" ); |
| 3 |
|
| 4 |
$(document).ready( function () { |
| 5 |
/* Check the default */ |
| 6 |
var oTable = $('#example').dataTable(); |
| 7 |
var oSettings = oTable.fnSettings(); |
| 8 |
var mPass; |
| 9 |
|
| 10 |
oTest.fnTest( |
| 11 |
"Default should be null", |
| 12 |
null, |
| 13 |
function () { return oSettings.fnFooterCallback == null; } |
| 14 |
); |
| 15 |
|
| 16 |
|
| 17 |
oTest.fnTest( |
| 18 |
"Five arguments passed", |
| 19 |
function () { |
| 20 |
oSession.fnRestore(); |
| 21 |
|
| 22 |
mPass = -1; |
| 23 |
$('#example').dataTable( { |
| 24 |
"fnFooterCallback": function ( ) { |
| 25 |
mPass = arguments.length; |
| 26 |
} |
| 27 |
} ); |
| 28 |
}, |
| 29 |
function () { return mPass == 5; } |
| 30 |
); |
| 31 |
|
| 32 |
|
| 33 |
oTest.fnTest( |
| 34 |
"fnRowCallback called once per draw", |
| 35 |
function () { |
| 36 |
oSession.fnRestore(); |
| 37 |
|
| 38 |
mPass = 0; |
| 39 |
$('#example').dataTable( { |
| 40 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 41 |
mPass++; |
| 42 |
} |
| 43 |
} ); |
| 44 |
}, |
| 45 |
function () { return mPass == 1; } |
| 46 |
); |
| 47 |
|
| 48 |
oTest.fnTest( |
| 49 |
"fnRowCallback called on paging (i.e. another draw)", |
| 50 |
function () { $('#example_next').click(); }, |
| 51 |
function () { return mPass == 2; } |
| 52 |
); |
| 53 |
|
| 54 |
|
| 55 |
oTest.fnTest( |
| 56 |
"fnRowCallback allows us to alter row information", |
| 57 |
function () { |
| 58 |
oSession.fnRestore(); |
| 59 |
$('#example').dataTable( { |
| 60 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 61 |
nFoot.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records"; |
| 62 |
} |
| 63 |
} ); |
| 64 |
}, |
| 65 |
function () { return $('#example tfoot th:eq(0)').html() == "Displaying 10 records"; } |
| 66 |
); |
| 67 |
|
| 68 |
|
| 69 |
oTest.fnTest( |
| 70 |
"Data array has length matching original data", |
| 71 |
function () { |
| 72 |
oSession.fnRestore(); |
| 73 |
|
| 74 |
mPass = true; |
| 75 |
$('#example').dataTable( { |
| 76 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 77 |
if ( aasData.length != 57 ) |
| 78 |
{ |
| 79 |
mPass = false; |
| 80 |
} |
| 81 |
} |
| 82 |
} ); |
| 83 |
}, |
| 84 |
function () { return mPass; } |
| 85 |
); |
| 86 |
|
| 87 |
oTest.fnTest( |
| 88 |
"Data array's column lengths match original data", |
| 89 |
function () { |
| 90 |
oSession.fnRestore(); |
| 91 |
|
| 92 |
mPass = true; |
| 93 |
$('#example').dataTable( { |
| 94 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 95 |
for ( var i=0, iLen=aasData.length ; i<iLen ; i++ ) |
| 96 |
{ |
| 97 |
if ( aasData[i].length != 5 ) |
| 98 |
{ |
| 99 |
mPass = false; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} ); |
| 104 |
}, |
| 105 |
function () { return mPass; } |
| 106 |
); |
| 107 |
|
| 108 |
|
| 109 |
oTest.fnTest( |
| 110 |
"iStart correct on first page", |
| 111 |
function () { |
| 112 |
oSession.fnRestore(); |
| 113 |
|
| 114 |
mPass = true; |
| 115 |
$('#example').dataTable( { |
| 116 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 117 |
if ( iStart != 0 ) |
| 118 |
{ |
| 119 |
mPass = false; |
| 120 |
} |
| 121 |
} |
| 122 |
} ); |
| 123 |
}, |
| 124 |
function () { return mPass; } |
| 125 |
); |
| 126 |
|
| 127 |
|
| 128 |
oTest.fnTest( |
| 129 |
"iStart correct on second page", |
| 130 |
function () { |
| 131 |
oSession.fnRestore(); |
| 132 |
|
| 133 |
mPass = false; |
| 134 |
$('#example').dataTable( { |
| 135 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 136 |
if ( iStart == 10 ) |
| 137 |
{ |
| 138 |
mPass = true; |
| 139 |
} |
| 140 |
} |
| 141 |
} ); |
| 142 |
$('#example_next').click(); |
| 143 |
}, |
| 144 |
function () { return mPass; } |
| 145 |
); |
| 146 |
|
| 147 |
|
| 148 |
oTest.fnTest( |
| 149 |
"iEnd correct on first page", |
| 150 |
function () { |
| 151 |
oSession.fnRestore(); |
| 152 |
|
| 153 |
mPass = true; |
| 154 |
$('#example').dataTable( { |
| 155 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 156 |
if ( iEnd != 10 ) |
| 157 |
{ |
| 158 |
mPass = false; |
| 159 |
} |
| 160 |
} |
| 161 |
} ); |
| 162 |
}, |
| 163 |
function () { return mPass; } |
| 164 |
); |
| 165 |
|
| 166 |
|
| 167 |
oTest.fnTest( |
| 168 |
"iEnd correct on second page", |
| 169 |
function () { |
| 170 |
oSession.fnRestore(); |
| 171 |
|
| 172 |
mPass = false; |
| 173 |
$('#example').dataTable( { |
| 174 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 175 |
if ( iEnd == 20 ) |
| 176 |
{ |
| 177 |
mPass = true; |
| 178 |
} |
| 179 |
} |
| 180 |
} ); |
| 181 |
$('#example_next').click(); |
| 182 |
}, |
| 183 |
function () { return mPass; } |
| 184 |
); |
| 185 |
|
| 186 |
|
| 187 |
oTest.fnTest( |
| 188 |
"aiDisplay length is full data when not filtered", |
| 189 |
function () { |
| 190 |
oSession.fnRestore(); |
| 191 |
|
| 192 |
mPass = false; |
| 193 |
$('#example').dataTable( { |
| 194 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 195 |
if ( aiDisplay.length == 57 ) |
| 196 |
{ |
| 197 |
mPass = true; |
| 198 |
} |
| 199 |
} |
| 200 |
} ); |
| 201 |
}, |
| 202 |
function () { return mPass; } |
| 203 |
); |
| 204 |
|
| 205 |
oTest.fnTest( |
| 206 |
"aiDisplay length is 9 when filtering on 'Mozilla'", |
| 207 |
function () { |
| 208 |
oSession.fnRestore(); |
| 209 |
|
| 210 |
mPass = false; |
| 211 |
oTable = $('#example').dataTable( { |
| 212 |
"fnFooterCallback": function ( nFoot, aasData, iStart, iEnd, aiDisplay ) { |
| 213 |
if ( aiDisplay.length == 9 ) |
| 214 |
{ |
| 215 |
mPass = true; |
| 216 |
} |
| 217 |
} |
| 218 |
} ); |
| 219 |
oTable.fnFilter( "Mozilla" ); |
| 220 |
}, |
| 221 |
function () { return mPass; } |
| 222 |
); |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
oTest.fnComplete(); |
| 227 |
} ); |