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