annotate DataTables-1.9.4/media/unit_testing/tests_onhold/6_delayed_rendering/fnRowCallback.js @ 0:ac5f9272033b draft

first upload
author saskia-hiltemann
date Tue, 01 Jul 2014 11:42:23 -0400
parents
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( "fnRowCallback" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 /* Note - fnRowCallback MUST return the first arguments (modified or not) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 $(document).ready( function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 /* Check the default */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 var oTable = $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 "bDeferRender": true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 var oSettings = oTable.fnSettings();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 var mPass;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 "Default should be null",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 function () { return oSettings.fnRowCallback == null; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 "Four arguments passed",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 mPass = -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 "fnRowCallback": function ( nTr ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 mPass = arguments.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 return nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 }
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 function () { return mPass == 4; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 );
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 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 "fnRowCallback called once for each drawn row",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 mPass = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 mPass++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 return nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 function () { return mPass == 10; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 "fnRowCallback allows us to alter row information",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 $(nTr).addClass('unit_test');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 return nTr;
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 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 function () { return $('#example tbody tr:eq(1)').hasClass('unit_test'); }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 "Data array has length matching columns",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 if ( asData.length != 5 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 return nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 oTest.fnWaitTest(
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 "Data array has length matching columns",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 oSession.fnRestore();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 mPass = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 var iCount = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 $('#example').dataTable( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 "bDeferRender": true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 if ( iCount != iDrawIndex )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 mPass = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 iCount++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 return nTr;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 function () { return mPass; }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 oTest.fnComplete();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 } );