Add datatables-1.9.4 and jquery-1.10.2 libraries
[proteocache.git] / webapp / resources / datatables-1.9.4 / media / unit_testing / tests_onhold / 4_server-side / fnRowCallback.js
1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "fnRowCallback" );
3
4 /* Note - fnRowCallback MUST return the first arguments (modified or not) */
5
6 $(document).ready( function () {
7         /* Check the default */
8         var oTable = $('#example').dataTable( {
9                 "bServerSide": true,
10                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php"
11         } );
12         var oSettings = oTable.fnSettings();
13         var mPass;
14         
15         oTest.fnWaitTest( 
16                 "Default should be null",
17                 null,
18                 function () { return oSettings.fnRowCallback == null; }
19         );
20         
21         
22         oTest.fnWaitTest( 
23                 "Four arguments passed",
24                 function () {
25                         oSession.fnRestore();
26                         
27                         mPass = -1;
28                         $('#example').dataTable( {
29                                 "bServerSide": true,
30                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php",
31                                 "fnRowCallback": function ( nTr ) {
32                                         mPass = arguments.length;
33                                         return nTr;
34                                 }
35                         } );
36                 },
37                 function () { return mPass == 4; }
38         );
39         
40         
41         oTest.fnWaitTest( 
42                 "fnRowCallback called once for each drawn row",
43                 function () {
44                         oSession.fnRestore();
45                         
46                         mPass = 0;
47                         $('#example').dataTable( {
48                                 "bServerSide": true,
49                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php",
50                                 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
51                                         mPass++;
52                                         return nTr;
53                                 }
54                         } );
55                 },
56                 function () { return mPass == 10; }
57         );
58         
59         oTest.fnWaitTest( 
60                 "fnRowCallback allows us to alter row information",
61                 function () {
62                         oSession.fnRestore();
63                         $('#example').dataTable( {
64                                 "bServerSide": true,
65                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php",
66                                 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
67                                         $(nTr).addClass('unit_test');
68                                         return nTr;
69                                 }
70                         } );
71                 },
72                 function () { return $('#example tbody tr:eq(1)').hasClass('unit_test'); }
73         );
74         
75         oTest.fnWaitTest( 
76                 "Data array has length matching columns",
77                 function () {
78                         oSession.fnRestore();
79                         
80                         mPass = true;
81                         $('#example').dataTable( {
82                                 "bServerSide": true,
83                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php",
84                                 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
85                                         if ( asData.length != 5 )
86                                                 mPass = false;
87                                         return nTr;
88                                 }
89                         } );
90                 },
91                 function () { return mPass; }
92         );
93         
94         oTest.fnWaitTest( 
95                 "Data array has length matching columns",
96                 function () {
97                         oSession.fnRestore();
98                         
99                         mPass = true;
100                         var iCount = 0;
101                         $('#example').dataTable( {
102                                 "bServerSide": true,
103                 "sAjaxSource": "../../../examples/server_side/scripts/server_processing.php",
104                                 "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
105                                         if ( iCount != iDrawIndex )
106                                                 mPass = false;
107                                         iCount++;
108                                         return nTr;
109                                 }
110                         } );
111                 },
112                 function () { return mPass; }
113         );
114         
115         
116         
117         oTest.fnComplete();
118 } );