1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | // DATA_TEMPLATE: dom_data oTest.fnStart( "aaSorting" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable(); var oSettings = oTable.fnSettings(); oTest.fnTest( "Default sorting is single column", null, function () { return oSettings.aaSorting.length == 1 && typeof oSettings.aaSorting[0] == 'object'; } ); oTest.fnTest( "Default sorting is first column asc", null, function () { return oSettings.aaSorting[0].length == 3 && oSettings.aaSorting[0][0] == 0 && oSettings.aaSorting[0][1] == 'asc'; } ); oTest.fnTest( "Sorting is applied", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Custom sorting on single string column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Custom sorting on single string column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Custom sorting on single int column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Custom sorting on single int column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','asc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Camino 1.0"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string asc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','asc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string desc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','desc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "iPod Touch / iPhone"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string desc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','desc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Safari 3.0"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string asc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','asc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string asc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','asc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1.9"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string desc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','desc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "125.5"; } ); oTest.fnTest( "Multi-column sorting (2 column) - string desc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','desc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Multi-column sorting (3 column) - string asc / int asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "aaSorting": [['0','asc'], ['3','asc'], ['1','asc']] } ); }, function () { return $('#example tbody tr:eq(7) td:eq(1)').html() == "Firefox 1.0"; } ); oTest.fnComplete(); } ); |