diff --git a/docs/index.html b/docs/index.html index 4ec5f05b..911954a4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -527,7 +527,7 @@
  • Duration parser (v2.17.8).
  • File type parser (v2.13).
  • Ignore leading articles parser (Ignore "A", "An" and "The" in titles) (v2.8).
  • -
  • Input/select parsers (used by Grouping rows widget) (v2.8; v2.17.5).
  • +
  • Input/select parsers (used by Grouping rows widget) (v2.8; v2.18.5).
  • Feet-inch-fraction parser (v2.8).
  • Metric parser (v2.8).
  • Named Numbers parser (v2.18.0).
  • @@ -1215,6 +1215,25 @@ From the example function above, you'll end up with something similar to this HT Example + + + Boolean + true + When this option is true any applied sort on the table will be reapplied after an update method (v2.18.5). +
    +
    + Specifically, this option applies to the "updateAll", "update", "addRows" and "updateCell" methods and is checked after the method has completed updating the internal cache.
    +
    + If false, the widgets will still be refreshed for all but the "updateCell" method - this "updateCell" behavior was added in v2.18.5.
    +
    + Note when triggering one of the above methods, and passing a defined resort parameter, it will override this setting.
    +
    + Note if a sort is not reapplied, problems with some widgets may occur namely the grouping widget. +
    + + + + serverSideSorting Boolean @@ -4292,7 +4311,8 @@ $.extend($.tablesorter.themes.jui, { '<td>$19.99</td><td>15%</td><td>Sep 25, 1987 12:00PM</td></tr>', $row = $(row), // resort table using true to reapply the current sort; set to false to prevent resort - // as of v2.18.5, the resort variable can contain a new sortList to be applied + // if undefined, the resort value will be obtained from config.resort (added v2.18.5) + // As of v2.18.5, the resort variable can contain a new sortList to be applied // A callback method was added in 2.3.9. resort = true, // or [[0,0],[1,0]] etc callback = function(table){ @@ -4377,7 +4397,7 @@ $("table").trigger("sortReset", [callback]); / - Update the tbody's stored data (update & updateRows do exactly the same thing) + Update the tbody's stored data (update & updateRows do exactly the same thing; v2.18.5)

    // Add new content
     $("table tbody").append(html);
    @@ -4392,6 +4412,8 @@ var resort = true,
         };
     $("table").trigger("update", [resort, callback]);
     
    +// As of version 2.18.5, if the resort parameter is undefined, the setting from the config.resort will be used
    +
     // As of version 2.0.14, the table will automatically resort after the update (if the "resort" flag is true
     // & will use the current sort selection), so include the following if you want to specify a different sort
     
    @@ -4412,7 +4434,7 @@ $('table').trigger('update', [ sorting ]);
    - Update a column of cells (thead and tbody) (v2.8). + Update a column of cells (thead and tbody) (v2.8; v2.18.5).
    // Change thead & tbody column of cells
     // remember, "eq()" is zero based & "nth-child()" is 1 based
    @@ -4424,6 +4446,7 @@ $("table tbody").find('td:nth-child(3)').html(function(i,h){
     
     // reapply the current sort if resort = true
     // do not reapply the current sort if resort = false
    +// if undefined, resort will be obtained from config.resort (added v2.18.5)
     // as of v2.18.5, apply a new sort if resort = [[0,0]] (or whatever)
     // or the sort is reset if resort = []
     var resort = true,
    @@ -4474,7 +4497,7 @@ $("table")
     
     			
     				
    -				Update a table cell in the tablesorter data.
    +				Update a table cell in the tablesorter data (v2.18.5).
     					
    $(function() {
       $("table").tablesorter();
    @@ -4483,6 +4506,7 @@ $("table")
     
         // Do we want to reapply the current sort on the column?
         // see updateRow for other resort settings as of v2.18.5
    +    // if resort is undefined, the value from config.resort (added v2.18.5) will be used
         var resort = false,
             // Do something after the cell update in this callback function
             callback = function(table){
    diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js
    index a50d6df4..b6a2a5d5 100644
    --- a/js/jquery.tablesorter.js
    +++ b/js/jquery.tablesorter.js
    @@ -56,6 +56,7 @@
     				usNumberFormat   : true,       // false for German "1.234.567,89" or French "1 234 567,89"
     				delayInit        : false,      // if false, the parsed table contents will not update until the first sort
     				serverSideSorting: false,      // if true, server-side sorting should be performed because client-side sorting will be disabled, but the ui and events will still be used.
    +				resort           : true,       // default setting to trigger a resort after an "update", "addRows", "updateCell", etc has completed
     
     				// *** sort options
     				headers          : {},         // set sorter, string, empty, locked order, sortInitialOrder, filter, etc.
    @@ -823,10 +824,12 @@
     			}
     
     			function checkResort(c, resort, callback) {
    -				var sl = $.isArray(resort) ? resort : c.sortList;
    +				var sl = $.isArray(resort) ? resort : c.sortList,
    +					// if no resort parameter is passed, fallback to config.resort (true by default)
    +					resrt = typeof resort === 'undefined' ? c.resort : resort;
     				// don't try to resort if the table is still processing
     				// this will catch spamming of the updateCell method
    -				if (resort !== false && !c.serverSideSorting && !c.table.isProcessing) {
    +				if (resrt !== false && !c.serverSideSorting && !c.table.isProcessing) {
     					if (sl.length) {
     						c.$table.trigger('sorton', [sl, function(){
     							resortComplete(c, callback);
    @@ -906,7 +909,18 @@
     							// update column max value (ignore sign)
     							c.cache[tbdy].colMax[icell] = Math.max(Math.abs(v) || 0, c.cache[tbdy].colMax[icell] || 0);
     						}
    -						checkResort(c, resort, callback);
    +						v = resort !== 'undefined' ? resort : c.resort;
    +						if (v !== false) {
    +							// widgets will be reapplied
    +							checkResort(c, v, callback);
    +						} else {
    +							// don't reapply widgets is resort is false, just in case it causes
    +							// problems with element focus
    +							if ($.isFunction(callback)) {
    +								callback(table);
    +							}
    +							c.$table.trigger('updateComplete', c.table);
    +						}
     					}
     				})
     				.bind("addRows" + c.namespace, function(e, $row, resort, callback) {
    diff --git a/js/parsers/parser-input-select.js b/js/parsers/parser-input-select.js
    index e166ef9f..a01538f2 100644
    --- a/js/parsers/parser-input-select.js
    +++ b/js/parsers/parser-input-select.js
    @@ -1,18 +1,17 @@
     /*! input & select parsers for jQuery 1.7+ & tablesorter 2.7.11+
    - * Updated 9/15/2014 (v2.17.8)
    + * Updated 1/28/2015 (v2.18.5)
      * Demo: http://mottie.github.com/tablesorter/docs/example-widget-grouping.html
      */
     /*jshint browser: true, jquery:true, unused:false */
     ;(function($){
     "use strict";
     
    -	var resort = true, // resort table after update
    -		updateServer = function(event, $table, $input){
    -			// do something here to update your server, if needed
    -			// event = change event object
    -			// $table = jQuery object of the table that was just updated
    -			// $input = jQuery object of the input or select that was modified
    -		};
    +	var updateServer = function(event, $table, $input){
    +		// do something here to update your server, if needed
    +		// event = change event object
    +		// $table = jQuery object of the table that was just updated
    +		// $input = jQuery object of the input or select that was modified
    +	};
     
     	// Custom parser for parsing input values
     	// updated dynamically using the "change" function below
    @@ -98,26 +97,21 @@
     	// if this code interferes somehow, target the specific table $('#mytable'), instead of $('table')
     	$(function(){
     		$('table').on('tablesorter-initialized', function(){
    -			// this flag prevents the updateCell event from being spammed
    -			// it happens when you modify input text and hit enter
    -			var focused = false,
    -				restoreValue = function(isTbody){
    -					// focused = false; // uncomment this line to prevent auto-accepting changes
    -					// make sure we restore original values
    -					// isTbody is needed to prevent the select from closing in IE
    -					// see https://connect.microsoft.com/IE/feedbackdetail/view/962618/
    -					if (isTbody) {
    -						$(':focus').blur();
    -					}
    -					return;
    -				};
    +			var restoreValue = function(isTbody){
    +				// make sure we restore original values (trigger blur)
    +				// isTbody is needed to prevent the select from closing in IE
    +				// see https://connect.microsoft.com/IE/feedbackdetail/view/962618/
    +				if (isTbody) {
    +					$(':focus').blur();
    +				}
    +				return;
    +			};
     			// bind to .tablesorter (default class name)
     			$(this).children('tbody')
     			.on('mouseleave', function(e){
     				restoreValue(e.target.tagName === 'TBODY');
     			})
     			.on('focus', 'select, input, textarea', function(){
    -				focused = true;
     				$(this).data('ts-original-value', this.value);
     			})
     			.on('blur', 'input, textarea', function(){
    @@ -132,9 +126,10 @@
     					return;
     				}
     				// Update cell cache using... select: change, input: enter or textarea: alt + enter
    -				if ( ( e.type === 'change' && focused ) ||
    +				if ( ( e.type === 'change' ) ||
     					( e.type === 'keyup' && e.which === 13 && ( e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' && e.altKey ) ) ) {
    -					var $tar = $(e.target),
    +					var undef,
    +						$tar = $(e.target),
     						$cell = $tar.closest('td'),
     						$table = $cell.closest('table'),
     						indx = $cell[0].cellIndex,
    @@ -148,9 +143,9 @@
     					// ignore change event if nothing changed
     					if ($tar.val() !== $tar.data('ts-original-value')) {
     						$tar.data('ts-original-value', $tar.val());
    -						$table.trigger('updateCell', [ $tar.closest('td'), resort, function(){
    +						// pass undefined resort value so it falls back to config.resort setting
    +						$table.trigger('updateCell', [ $tar.closest('td'), undef, function(){
     							updateServer(e, $table, $tar);
    -							setTimeout(function(){ focused = false; }, 10);
     						} ]);
     					}
     				}