update method now enables/disables column sorting

This commit is contained in:
Mottie 2013-03-06 08:19:22 -06:00
parent cda213a496
commit a4fa0ed49c

View File

@ -370,13 +370,13 @@
function buildHeaders(table) { function buildHeaders(table) {
var header_index = computeThIndexes(table), ch, $t, var header_index = computeThIndexes(table), ch, $t,
h, i, t, lock, time, $tableHeaders, c = table.config; h, i, t, lock, time, c = table.config;
c.headerList = [], c.headerContent = []; c.headerList = [], c.headerContent = [];
if (c.debug) { if (c.debug) {
time = new Date(); time = new Date();
} }
i = c.cssIcon ? '<i class="' + c.cssIcon + '"></i>' : ''; // add icon if cssIcon option exists i = c.cssIcon ? '<i class="' + c.cssIcon + '"></i>' : ''; // add icon if cssIcon option exists
$tableHeaders = $(table).find(c.selectorHeaders).each(function(index) { c.$headers = $(table).find(c.selectorHeaders).each(function(index) {
$t = $(this); $t = $(this);
ch = c.headers[index]; ch = c.headers[index];
c.headerContent[index] = this.innerHTML; // save original header content c.headerContent[index] = this.innerHTML; // save original header content
@ -393,28 +393,34 @@
this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex]; this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2]; this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
this.count = -1; // set to -1 because clicking on the header automatically adds one this.count = -1; // set to -1 because clicking on the header automatically adds one
if (ts.getData($t, ch, 'sorter') === 'false') {
this.sortDisabled = true;
$t.addClass('sorter-false');
} else {
$t.removeClass('sorter-false');
}
this.lockedOrder = false; this.lockedOrder = false;
lock = ts.getData($t, ch, 'lockedOrder') || false; lock = ts.getData($t, ch, 'lockedOrder') || false;
if (typeof(lock) !== 'undefined' && lock !== false) { if (typeof(lock) !== 'undefined' && lock !== false) {
this.order = this.lockedOrder = formatSortingOrder(lock) ? [1,1,1] : [0,0,0]; this.order = this.lockedOrder = formatSortingOrder(lock) ? [1,1,1] : [0,0,0];
} }
$t.addClass( (this.sortDisabled ? 'sorter-false ' : ' ') + c.cssHeader ); $t.addClass(c.cssHeader);
// add cell to headerList // add cell to headerList
c.headerList[index] = this; c.headerList[index] = this;
// add to parent in case there are multiple rows // add to parent in case there are multiple rows
$t.parent().addClass(c.cssHeaderRow); $t.parent().addClass(c.cssHeaderRow);
}); });
if (table.config.debug) { // enable/disable sorting
updateHeader(table);
if (c.debug) {
benchmark("Built headers:", time); benchmark("Built headers:", time);
log($tableHeaders); log(c.$headers);
} }
return $tableHeaders; }
function updateHeader(table) {
var s, th,
c = table.config;
c.$headers.each(function(index, th){
s = ts.getData( th, c.headers[index], 'sorter' ) === 'false';
th.sortDisabled = s;
// $t.toggleClass('sorter-false', this.sortDisabled); not supported until jQuery 1.3
$(th)[ s ? 'addClass' : 'removeClass' ]('sorter-false');
});
} }
function setHeadersCss(table) { function setHeadersCss(table) {
@ -568,7 +574,7 @@
c.$table = $this.addClass(c.tableClass + k); c.$table = $this.addClass(c.tableClass + k);
c.$tbodies = $this.children('tbody:not(.' + c.cssInfoBlock + ')'); c.$tbodies = $this.children('tbody:not(.' + c.cssInfoBlock + ')');
// build headers // build headers
c.$headers = buildHeaders($t0); buildHeaders($t0);
// fixate columns if the users supplies the fixedWidth option // fixate columns if the users supplies the fixedWidth option
// do this after theme has been applied // do this after theme has been applied
fixColumnWidth($t0); fixColumnWidth($t0);
@ -714,6 +720,8 @@
.bind("update.tablesorter updateRows.tablesorter", function(e, resort, callback) { .bind("update.tablesorter updateRows.tablesorter", function(e, resort, callback) {
// remove rows/elements before update // remove rows/elements before update
$this.find(c.selectorRemove).remove(); $this.find(c.selectorRemove).remove();
// update sorting
updateHeader($t0);
// rebuild parsers // rebuild parsers
c.parsers = buildParserCache($t0); c.parsers = buildParserCache($t0);
// rebuild the cache map // rebuild the cache map