Add datatables-1.9.4 and jquery-1.10.2 libraries
[proteocache.git] / webapp / resources / datatables-1.9.4 / media / unit_testing / tests_onhold / 2_js / aoColumns.fnRender.js
1 // DATA_TEMPLATE: js_data
2 oTest.fnStart( "aoColumns.fnRender" );
3
4 $(document).ready( function () {
5         /* Check the default */
6         var mTmp = 0;
7         var oTable = $('#example').dataTable( {
8                 "aaData": gaaData,
9                 "aoColumns": [
10                         null,
11                         { "fnRender": function (a) {
12                                 mTmp++;
13                                 return a.aData[a.iDataColumn];
14                         } },
15                         null,
16                         null,
17                         null
18                 ]
19         } );
20         var oSettings = oTable.fnSettings();
21         
22         oTest.fnTest( 
23                 "Single column - fnRender is called once for each row",
24                 null,
25                 function () { return mTmp == 57; }
26         );
27         
28         oTest.fnTest( 
29                 "Confirm that fnRender passes two arguments with four parameters",
30                 function () {
31                         mTmp = true;
32                         oSession.fnRestore();
33                         oTable = $('#example').dataTable( {
34                                 "aaData": gaaData,
35                                 "aoColumns": [
36                                         null,
37                                         { "fnRender": function (a) {
38                                                 if ( arguments.length != 2 || typeof a.iDataRow=='undefined' ||
39                                                         typeof a.iDataColumn=='undefined' || typeof a.aData=='undefined' ||
40                                                         typeof a.mDataProp=='undefined' )
41                                                 {
42                                                         mTmp = false;
43                                                 }
44                                                 return a.aData[a.iDataColumn];
45                                         } },
46                                         null,
47                                         null,
48                                         null
49                                 ]
50                         } );
51                 },
52                 function () { return mTmp; }
53         );
54         
55         oTest.fnTest( 
56                 "fnRender iDataColumn is the column",
57                 function () {
58                         mTmp = true;
59                         oSession.fnRestore();
60                         oTable = $('#example').dataTable( {
61                                 "aaData": gaaData,
62                                 "aoColumns": [
63                                         null,
64                                         { "fnRender": function (a) {
65                                                 if ( a.iDataColumn != 1 )
66                                                 {
67                                                         mTmp = false;
68                                                 }
69                                                 return a.aData[a.iDataColumn];
70                                         } },
71                                         null,
72                                         null,
73                                         null
74                                 ]
75                         } );
76                 },
77                 function () { return mTmp; }
78         );
79         
80         oTest.fnTest( 
81                 "fnRender aData is data array of correct size",
82                 function () {
83                         mTmp = true;
84                         oSession.fnRestore();
85                         oTable = $('#example').dataTable( {
86                                 "aaData": gaaData,
87                                 "aoColumns": [
88                                         null,
89                                         { "fnRender": function (a) {
90                                                 if ( a.aData.length != 5 )
91                                                 {
92                                                         mTmp = false;
93                                                 }
94                                                 return a.aData[a.iDataColumn];
95                                         } },
96                                         null,
97                                         null,
98                                         null
99                                 ]
100                         } );
101                 },
102                 function () { return mTmp; }
103         );
104         
105         oTest.fnTest( 
106                 "Passed back data is put into the DOM",
107                 function () {
108                         oSession.fnRestore();
109                         oTable = $('#example').dataTable( {
110                                 "aaData": gaaData,
111                                 "aoColumns": [
112                                         null,
113                                         { "fnRender": function (a) {
114                                                 return 'unittest';
115                                         } },
116                                         null,
117                                         null,
118                                         null
119                                 ]
120                         } );
121                 },
122                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'unittest'; }
123         );
124         
125         oTest.fnTest( 
126                 "Passed back data is put into the DOM",
127                 function () {
128                         oSession.fnRestore();
129                         oTable = $('#example').dataTable( {
130                                 "aaData": gaaData,
131                                 "aoColumns": [
132                                         null,
133                                         null,
134                                         { "fnRender": function (a) {
135                                                 return 'unittest1';
136                                         } },
137                                         { "fnRender": function (a) {
138                                                 return 'unittest2';
139                                         } },
140                                         null
141                                 ]
142                         } );
143                 },
144                 function () {
145                         var bReturn = 
146                                 $('#example tbody tr:eq(0) td:eq(2)').html() == 'unittest1' &&
147                                 $('#example tbody tr:eq(0) td:eq(3)').html() == 'unittest2';
148                         return bReturn; }
149         );
150         
151         
152         
153         
154         
155         oTest.fnComplete();
156 } );