// Stupid jQuery table plugin. //http://joequery.github.com/Stupid-Table-Plugin/ // Call on a table // sortFns: Sort functions for your datatypes. (function($){ $.fn.stupidtable = function(sortFns){ var table = this; sortFns = sortFns || {}; // ==================================================== // // Utility functions // // ==================================================== // // Merge sort functions with some default sort functions. sortFns = $.extend({}, { "int":function(a,b){ return parseInt(a, 10) - parseInt(b, 10); }, "float":function(a,b){ return parseFloat(a) - parseFloat(b); }, "string":function(a,b){ if (ab) return +1; return 0;} }, sortFns); // Array comparison. See http://stackoverflow.com/a/8618383 var arrays_equal = function(a,b) { return !!a && !!b && !(a=0; i--){ theMap.push(i); } }else{ // Get a sort map and apply to all rows theMap = sort_map(column, sortMethod); } // remove old sort classes (on this and other columns) $(this).parent().find('th').each(function() { $(this).removeClass('sortasc sortdesc'); }); // what order are we sorting in? var whatorder = what_order_sorted(column, sortMethod, is_sorted_array(column, sortMethod)); // set new sort class $(this).addClass(whatorder == 'asc' ? 'sortasc' : 'sortdesc'); var sortedTRs = $(apply_sort_map(trs, theMap)); // Replace the content of tbody with the sortedTRs. Strangely (and // conveniently!) enough, .append accomplishes this for us. table.find("tbody").append(sortedTRs); }); // remove th icon if no header text $(this).find('th').each(function() { var hv = $(this).text().replace(/ /g, ''); if(hv == '') { $(this).css('background-image', 'none'); } }); } })(jQuery); $('table.sortable').each(function() { var rows = $(this).find('tbody tr').length; if(rows > 1) { $(this).stupidtable(); }else{ $(this).removeClass('sortable'); } });