Editable: autoresort true no longer breaks the table

This commit is contained in:
Mottie 2014-08-26 13:33:56 -05:00
parent 7747fa9700
commit 1606cca123

View File

@ -21,7 +21,17 @@
init: function(table, thisWidget, c, wo){ init: function(table, thisWidget, c, wo){
if ( !wo.editable_columns.length ) { return; } if ( !wo.editable_columns.length ) { return; }
var indx, tmp, $t, var indx, tmp, $t,
cols = []; cols = [],
editComplete = function($cell){
$cell
.removeClass('tseditable-last-edited-cell')
.trigger( wo.editable_editComplete, [c] );
// restore focus last cell after updating
setTimeout(function(){
$cell.focus();
}, 50);
};
if ( $.type(wo.editable_columns) === "string" && wo.editable_columns.indexOf('-') >= 0 ) { if ( $.type(wo.editable_columns) === "string" && wo.editable_columns.indexOf('-') >= 0 ) {
// editable_columns can contain a range string (i.e. "2-4" ) // editable_columns can contain a range string (i.e. "2-4" )
tmp = wo.editable_columns.split('-'); tmp = wo.editable_columns.split('-');
@ -83,26 +93,27 @@
if ( t && $this.data('before') !== $this.html() ) { if ( t && $this.data('before') !== $this.html() ) {
valid = $.isFunction(wo.editable_validate) ? wo.editable_validate( $this.html(), $this.data('original') ) : $this.html(); valid = $.isFunction(wo.editable_validate) ? wo.editable_validate( $this.html(), $this.data('original') ) : $this.html();
if ( t && valid !== false ) { if ( t && valid !== false ) {
c.$table.find('.tseditable-last-edited-cell').removeClass('tseditable-last-edited-cell');
$this $this
.addClass('tseditable-last-edited-cell')
.html( valid ) .html( valid )
.data('before', valid) .data('before', valid)
.data('original', valid)
.trigger('change'); .trigger('change');
c.$table.trigger('updateCell', [ $this.closest('td'), wo.editable_autoResort, function(table){ c.$table.trigger('updateCell', [ $this.closest('td'), false, function(table){
$this.trigger( wo.editable_editComplete, [c] ); if (wo.editable_autoResort) {
$this.data( 'original', $this.html() );
if ( wo.editable_autoResort && c.sortList.length ) {
c.$table.trigger('applyWidgets');
}
// restore focus last cell after updating
setTimeout(function(){ setTimeout(function(){
var t = c.$table.data('contentFocused'); c.$table.trigger("sorton", [ c.sortList, function(){
if ( t instanceof HTMLElement ) { t.focus(); } editComplete(c.$table.find('.tseditable-last-edited-cell'));
}, 50); }, true ]);
}, 10);
} else {
editComplete(c.$table.find('.tseditable-last-edited-cell'));
}
} ]); } ]);
return false; return false;
} }
} } else if ( !valid && e.type !== 'keydown' ) {
if ( !valid && e.type !== 'keydown' ) {
// restore original content on blur // restore original content on blur
$this.html( $this.data('original') ); $this.html( $this.data('original') );
} }