161c41212c5aad4cddf8affd19d9d13170e3cbe1
[proteocache.git] / webapp / resources / datatables-1.9.4 / media / unit_testing / tests_onhold / 1_dom / aoColumns.bUseRendered.js
1 // DATA_TEMPLATE: dom_data
2 oTest.fnStart( "aoColumns.bUseRendered" );
3
4 /* bUseRendered is used to alter sorting data, if false then the original data is used for
5  * sorting rather than the rendered data
6  */
7
8 $(document).ready( function () {
9         /* Check the default */
10         var mTmp = 0;
11         
12         var oTable = $('#example').dataTable( {
13                 "aoColumns": [
14                         null,
15                         { "fnRender": function (a) {
16                                 if ( mTmp == 0 ) {
17                                         mTmp++;
18                                         return "aaa";
19                                 } else
20                                         return a.aData[a.iDataColumn];
21                         } },
22                         null,
23                         null,
24                         null
25                 ]
26         } );
27         var oSettings = oTable.fnSettings();
28         
29         oTest.fnTest( 
30                 "Default for bUseRendered is true - rendered data is used for sorting",
31                 function () { $('#example thead th:eq(1)').click(); },
32                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'aaa'; }
33         );
34         
35         oTest.fnTest( 
36                 "When bUseRendered is false, original data is used for sorting",
37                 function () {
38                         mTmp = 0;
39                         oSession.fnRestore();
40                         oTable = $('#example').dataTable( {
41                                 "aoColumns": [
42                                         null,
43                                         { 
44                                                 "bUseRendered": false,
45                                                 "fnRender": function (a) {
46                                                         if ( mTmp == 0 ) {
47                                                                 mTmp++;
48                                                                 return "aaa";
49                                                         } else {
50                                                                 return a.aData[a.iDataColumn];
51                                                         }
52                                                 }
53                                         },
54                                         null,
55                                         null,
56                                         null
57                                 ]
58                         } );
59                         $('#example thead th:eq(1)').click();
60                 },
61                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; }
62         );
63         
64         
65         oTest.fnTest( 
66                 "bUseRendered set to false on one columns and true (default) on two others",
67                 function () {
68                         mTmp = 0;
69                         var mTmp2 = 0;
70                         var mTmp3 = 0;
71                         
72                         oSession.fnRestore();
73                         oTable = $('#example').dataTable( {
74                                 "aoColumns": [
75                                         {
76                                                 "fnRender": function (a) {
77                                                         if ( mTmp == 0 ) {
78                                                                 mTmp++;
79                                                                 return "aaa1";
80                                                         } else {
81                                                                 return a.aData[a.iDataColumn];
82                                                         }
83                                                 }
84                                         },
85                                         { 
86                                                 "bUseRendered": false,
87                                                 "fnRender": function (a) {
88                                                         if ( mTmp2 == 0 ) {
89                                                                 mTmp2++;
90                                                                 return "aaa2";
91                                                         } else {
92                                                                 return a.aData[a.iDataColumn];
93                                                         }
94                                                 }
95                                         },
96                                         {
97                                                 "fnRender": function (a) {
98                                                         if ( mTmp3 == 0 ) {
99                                                                 mTmp3++;
100                                                                 return "zzz3";
101                                                         } else {
102                                                                 return a.aData[a.iDataColumn];
103                                                         }
104                                                 }
105                                         },
106                                         null,
107                                         null
108                                 ]
109                         } );
110                 },
111                 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'aaa1'; }
112         );
113         
114         oTest.fnTest( 
115                 "Multi-column rendering - 2nd column sorting",
116                 function () { $('#example thead th:eq(1)').click(); },
117                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; }
118         );
119         
120         oTest.fnTest( 
121                 "Multi-column rendering - 3rd column sorting",
122                 function () {
123                         $('#example thead th:eq(2)').click();
124                         $('#example thead th:eq(2)').click();
125                 },
126                 function () { return $('#example tbody tr:eq(0) td:eq(2)').html() == 'zzz3'; }
127         );
128         
129         oTest.fnTest( 
130                 "Multi-column rendering - 4th column sorting",
131                 function () { $('#example thead th:eq(3)').click(); },
132                 function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == '-'; }
133         );
134         
135         oTest.fnTest( 
136                 "Multi-column rendering - 5th column sorting",
137                 function () { $('#example thead th:eq(4)').click(); },
138                 function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; }
139         );
140         
141         
142         
143         
144         oTest.fnComplete();
145 } );