From 7851a6a204a4a71e2ab5798174a497bd789a92af Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 19 Mar 2015 16:20:34 +0000 Subject: [PATCH] Fix: If `async:false` is used in the Ajax configuration, callbacks assigned with `dt-api ajax.reload()` would not trigger until another draw has been executed. This was due simply to the code ordering for how the callback is triggered. See https://www.datatables.net/forums/discussion/26474 for more information. --- .datatables-commit-sync | 2 +- media/js/jquery.dataTables.js | 19 +++++++++---------- media/js/jquery.dataTables.min.js | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 79ba06b9..3bd7918d 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -8847bf4fc89d841b8d39011c6c05636b4d2331ac +7276c8a1f2cb28f8b1b11f29412676b42f1be21b diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 586c6a45..ffded4c5 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -7366,6 +7366,15 @@ var __reload = function ( settings, holdPosition, callback ) { + // Use the draw event to trigger a callback + if ( callback ) { + var api = new _Api( settings ); + + api.one( 'draw', function () { + callback( api.ajax.json() ); + } ); + } + if ( _fnDataSource( settings ) == 'ssp' ) { _fnReDraw( settings, holdPosition ); } @@ -7385,16 +7394,6 @@ _fnProcessingDisplay( settings, false ); } ); } - - // Use the draw event to trigger a callback, regardless of if it is an async - // or sync draw - if ( callback ) { - var api = new _Api( settings ); - - api.one( 'draw', function () { - callback( api.ajax.json() ); - } ); - } }; diff --git a/media/js/jquery.dataTables.min.js b/media/js/jquery.dataTables.min.js index 5eb321d1..c573efa4 100644 --- a/media/js/jquery.dataTables.min.js +++ b/media/js/jquery.dataTables.min.js @@ -100,7 +100,7 @@ typeof f.val?h(a,f.val,f):g.isPlainObject(f.val)?{}:f.val,b[f.name].__dt_wrapper t.registerPlural=u=function(a,b,c){t.register(a,c);t.register(b,function(){var a=c.apply(this,arguments);return a===this?this:a instanceof t?a.length?g.isArray(a[0])?new t(a.context,a[0]):a[0]:k:a})};r("tables()",function(a){var b;if(a){b=t;var c=this.context;if("number"===typeof a)a=[c[a]];else var e=g.map(c,function(a){return a.nTable}),a=g(e).filter(a).map(function(){var a=g.inArray(this,e);return c[a]}).toArray();b=new b(a)}else b=this;return b});r("table()",function(a){var a=this.tables(a),b= a.context;return b.length?new t(b[0]):a});u("tables().nodes()","table().node()",function(){return this.iterator("table",function(a){return a.nTable},1)});u("tables().body()","table().body()",function(){return this.iterator("table",function(a){return a.nTBody},1)});u("tables().header()","table().header()",function(){return this.iterator("table",function(a){return a.nTHead},1)});u("tables().footer()","table().footer()",function(){return this.iterator("table",function(a){return a.nTFoot},1)});u("tables().containers()", "table().container()",function(){return this.iterator("table",function(a){return a.nTableWrapper},1)});r("draw()",function(a){return this.iterator("table",function(b){N(b,!1===a)})});r("page()",function(a){return a===k?this.page.info().page:this.iterator("table",function(b){Ta(b,a)})});r("page.info()",function(){if(0===this.context.length)return k;var a=this.context[0],b=a._iDisplayStart,c=a._iDisplayLength,e=a.fnRecordsDisplay(),d=-1===c;return{page:d?0:Math.floor(b/c),pages:d?1:Math.ceil(e/c),start:b, -end:a.fnDisplayEnd(),length:c,recordsTotal:a.fnRecordsTotal(),recordsDisplay:e}});r("page.len()",function(a){return a===k?0!==this.context.length?this.context[0]._iDisplayLength:k:this.iterator("table",function(b){Ra(b,a)})});var Ub=function(a,b,c){"ssp"==B(a)?N(a,b):(C(a,!0),ra(a,[],function(c){oa(a);for(var c=sa(a,c),e=0,h=c.length;e