Changeset 352
- Timestamp:
- Nov 1, 2017, 10:57:07 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sorttable-klask.js
r344 r352 4 4 7th April 2007 5 5 Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ 6 6 7 7 Instructions: 8 8 Download this file … … 10 10 Add class="sortable" to any table you'd like to make sortable 11 11 Click on the headers to sort 12 12 13 13 Thanks to many, many people for contributions and suggestions. 14 14 Licenced as X11: http://www.kryogenix.org/code/browser/licence.html … … 16 16 */ 17 17 18 18 19 19 var stIsIE = /*@cc_on!@*/false; 20 20 … … 27 27 // kill the timer 28 28 if (_timer) clearInterval(_timer); 29 29 30 30 if (!document.createElement || !document.getElementsByTagName) return; 31 31 32 32 sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; 33 33 34 34 forEach(document.getElementsByTagName('table'), function(table) { 35 35 if (table.className.search(/\bsortable\b/) != -1) { … … 37 37 } 38 38 }); 39 40 }, 41 39 40 }, 41 42 42 makeSortable: function(table) { 43 43 if (table.getElementsByTagName('thead').length == 0) { … … 50 50 // Safari doesn't support table.tHead, sigh 51 51 if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; 52 52 53 53 if (table.tHead.rows.length != 1) return; // can't cope with two header rows 54 54 55 55 // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as 56 56 // "total" rows, for example). This is B&R, since what you're supposed … … 74 74 delete sortbottomrows; 75 75 } 76 76 77 77 // work through each column and calculate its type 78 78 headrow = table.tHead.rows[0].cells; … … 93 93 94 94 if (this.className.search(/\bsorttable_sorted\b/) != -1) { 95 // if we're already sorted by this column, just 95 // if we're already sorted by this column, just 96 96 // reverse the table, which is quicker 97 97 sorttable.reverse(this.sorttable_tbody); … … 106 106 } 107 107 if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { 108 // if we're already sorted by this column in reverse, just 108 // if we're already sorted by this column in reverse, just 109 109 // re-reverse the table, which is quicker 110 110 sorttable.reverse(this.sorttable_tbody); … … 118 118 return; 119 119 } 120 120 121 121 // remove sorttable_sorted classes 122 122 theadrow = this.parentNode; … … 131 131 sortrevind = document.getElementById('sorttable_sortrevind'); 132 132 if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } 133 133 134 134 this.className += ' sorttable_sorted'; 135 135 sortfwdind = document.createElement('span'); … … 152 152 /* and comment out this one */ 153 153 row_array.sort(this.sorttable_sortfunction); 154 154 155 155 tb = this.sorttable_tbody; 156 156 // gabriel … … 160 160 // gabriel 161 161 if ( memory != row_array[j][0] ) { 162 memory = row_array[j][0]; 162 memory = row_array[j][0]; 163 163 color = color =="odd" ? "even" : "odd"; 164 164 } … … 167 167 tb.appendChild(row_array[j][1]); 168 168 } 169 169 170 170 delete row_array; 171 171 }); … … 173 173 } 174 174 }, 175 175 176 176 guessType: function(table, column) { 177 177 // guess the type of a column based on its first non-blank row … … 183 183 return sorttable.sort_numeric; 184 184 } 185 // check for a date: dd/mm/yyyy or dd/mm/yy 185 // check for a date: dd/mm/yyyy or dd/mm/yy 186 186 // can have / or . or - as separator 187 187 // can be mm/dd as well … … 206 206 return sortfn; 207 207 }, 208 208 209 209 getInnerText: function(node) { 210 210 // gets the text we want to use for sorting for a cell. … … 213 213 // for example, you can override the cell text with a customkey attribute. 214 214 // it also gets .value for <input> fields. 215 215 216 216 hasInputs = (typeof node.getElementsByTagName == 'function') && 217 217 node.getElementsByTagName('input').length; 218 218 219 219 if (node.getAttribute("sorttable_customkey") != null) { 220 220 return node.getAttribute("sorttable_customkey"); … … 251 251 } 252 252 }, 253 253 254 254 reverse: function(tbody) { 255 255 // reverse the rows in a tbody … … 263 263 delete newrows; 264 264 }, 265 265 266 266 /* sort functions 267 267 each sort function takes two parameters, a and b … … 270 270 aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); 271 271 if (isNaN(aa)) aa = 0; 272 bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); 272 bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); 273 273 if (isNaN(bb)) bb = 0; 274 274 return aa-bb; … … 309 309 return 1; 310 310 }, 311 311 312 312 shaker_sort: function(list, comp_func) { 313 313 // A stable sort function to allow multi-level sorting of data … … 339 339 340 340 } // while(swap) 341 } 341 } 342 342 } 343 343
Note: See TracChangeset
for help on using the changeset viewer.