1 |
// DATA_TEMPLATE: js_data |
2 |
oTest.fnStart( "bSortClasses" ); |
3 |
|
4 |
$(document).ready( function () { |
5 |
/* Check the default */ |
6 |
$('#example').dataTable( { |
7 |
"aaData": gaaData |
8 |
} ); |
9 |
|
10 |
oTest.fnTest( |
11 |
"Sorting classes are applied by default", |
12 |
null, |
13 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } |
14 |
); |
15 |
|
16 |
oTest.fnTest( |
17 |
"Sorting classes are applied to all required cells", |
18 |
null, |
19 |
function () { return $('#example tbody tr:eq(7) td:eq(0)').hasClass('sorting_1'); } |
20 |
); |
21 |
|
22 |
oTest.fnTest( |
23 |
"Sorting classes are not applied to non-sorting columns", |
24 |
null, |
25 |
function () { return $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_1') == false; } |
26 |
); |
27 |
|
28 |
oTest.fnTest( |
29 |
"Sorting multi-column - add column 1", |
30 |
function () { |
31 |
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, |
32 |
function () { |
33 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && |
34 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2'); |
35 |
} |
36 |
); |
37 |
|
38 |
oTest.fnTest( |
39 |
"Sorting multi-column - add column 2", |
40 |
function () { |
41 |
oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, |
42 |
function () { |
43 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && |
44 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && |
45 |
$('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3'); |
46 |
} |
47 |
); |
48 |
|
49 |
oTest.fnTest( |
50 |
"Sorting multi-column - add column 3", |
51 |
function () { |
52 |
oDispacher.click( $('#example thead th:eq(3)')[0], { 'shift': true } ); |
53 |
}, |
54 |
function () { |
55 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && |
56 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && |
57 |
$('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') && |
58 |
$('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3'); |
59 |
} |
60 |
); |
61 |
|
62 |
oTest.fnTest( |
63 |
"Remove sorting classes on single column sort", |
64 |
function () { |
65 |
$('#example thead th:eq(4)').click(); |
66 |
}, |
67 |
function () { |
68 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && |
69 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && |
70 |
$('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false && |
71 |
$('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3') == false; |
72 |
} |
73 |
); |
74 |
|
75 |
oTest.fnTest( |
76 |
"Sorting class 1 was added", |
77 |
null, |
78 |
function () { return $('#example tbody tr:eq(1) td:eq(4)').hasClass('sorting_1'); } |
79 |
); |
80 |
|
81 |
|
82 |
/* Check can disable */ |
83 |
oTest.fnTest( |
84 |
"Sorting classes can be disabled", |
85 |
function () { |
86 |
oSession.fnRestore(); |
87 |
$('#example').dataTable( { |
88 |
"aaData": gaaData, |
89 |
"bSortClasses": false |
90 |
} ); |
91 |
}, |
92 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false; } |
93 |
); |
94 |
|
95 |
oTest.fnTest( |
96 |
"Sorting classes disabled - add column 1 - no effect", |
97 |
function () { |
98 |
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, |
99 |
function () { |
100 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && |
101 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false; |
102 |
} |
103 |
); |
104 |
|
105 |
oTest.fnTest( |
106 |
"Sorting classes disabled - add column 2 - no effect", |
107 |
function () { |
108 |
oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, |
109 |
function () { |
110 |
return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && |
111 |
$('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && |
112 |
$('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false; |
113 |
} |
114 |
); |
115 |
|
116 |
|
117 |
/* Enable makes no difference */ |
118 |
oTest.fnTest( |
119 |
"Sorting classes enabled override", |
120 |
function () { |
121 |
oSession.fnRestore(); |
122 |
$('#example').dataTable( { |
123 |
"aaData": gaaData, |
124 |
"bSortClasses": true |
125 |
} ); |
126 |
}, |
127 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } |
128 |
); |
129 |
|
130 |
|
131 |
oTest.fnComplete(); |
132 |
} ); |