Skip to content

Commit 6560302

Browse files
committed
Fix Datatable reload after click on select_all or reset_selection buttons
1 parent 9b12be6 commit 6560302

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

dist/js/datatables-factory.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ DatatableBase = function () {
442442
//######################
443443
// Instance attributes #
444444
//######################
445+
DatatableBase.prototype.datatable = null;
445446
DatatableBase.prototype.columns = [];
446447
DatatableBase.prototype.buttons = [];
447448
DatatableBase.prototype.filters = [];
@@ -2319,17 +2320,18 @@ Loader.instance_methods = {
23192320
return this.dt_options = $.extend({}, this.dt_options, local_opts);
23202321
},
23212322
_loader_load_buttons_callbacks: function _loader_load_buttons_callbacks() {
2322-
var _this2 = this;
2323+
var callback;
23232324
this.info('Build datatable callbacks options : buttons');
2325+
callback = function callback(dt_class, _data, _status, _xhr) {
2326+
var klass;
2327+
klass = Loader.class_methods.constantize(dt_class);
2328+
return klass.instance.datatable.ajax.reload();
2329+
};
23242330
this.callbacks['buttons']['select_all'] = {
2325-
success: [function (_data, _status, _xhr) {
2326-
return _this2.datatable.ajax.reload();
2327-
}]
2331+
success: [callback]
23282332
};
23292333
return this.callbacks['buttons']['reset_selection'] = {
2330-
success: [function (_data, _status, _xhr) {
2331-
return _this2.datatable.ajax.reload();
2332-
}]
2334+
success: [callback]
23332335
};
23342336
},
23352337
_select: function _select(obj, predicate) {
@@ -2505,7 +2507,8 @@ WithButtons.instance_methods = {
25052507
return this.buttons[idx] = button;
25062508
},
25072509
_build_ajax_options: function _build_ajax_options(button) {
2508-
var callbacks, on_error, on_send, on_success;
2510+
var callbacks, dt_class, on_error, on_send, on_success;
2511+
dt_class = this.dt_class;
25092512
callbacks = this.callbacks['buttons'][button];
25102513
on_send = callbacks.beforeSend != null ? callbacks.beforeSend : [];
25112514
on_error = callbacks.error != null ? callbacks.error : [];
@@ -2516,7 +2519,7 @@ WithButtons.instance_methods = {
25162519
results = [];
25172520
for (j = 0, len1 = on_send.length; j < len1; j++) {
25182521
c = on_send[j];
2519-
results.push(c(xhr, settings));
2522+
results.push(c(dt_class, xhr, settings));
25202523
}
25212524
return results;
25222525
},
@@ -2525,7 +2528,7 @@ WithButtons.instance_methods = {
25252528
results = [];
25262529
for (j = 0, len1 = on_error.length; j < len1; j++) {
25272530
c = on_error[j];
2528-
results.push(c(xhr, status, _error));
2531+
results.push(c(dt_class, xhr, status, _error));
25292532
}
25302533
return results;
25312534
},
@@ -2534,7 +2537,7 @@ WithButtons.instance_methods = {
25342537
results = [];
25352538
for (j = 0, len1 = on_success.length; j < len1; j++) {
25362539
c = on_success[j];
2537-
results.push(c(data, status, xhr));
2540+
results.push(c(dt_class, data, status, xhr));
25382541
}
25392542
return results;
25402543
}

src/model/datatable_base.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DatatableBase extends Extendable
4444
# Instance attributes #
4545
#######################
4646

47+
datatable: null
4748
columns: []
4849
buttons: []
4950
filters: []

src/modules/loader.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ Loader.instance_methods =
186186
_loader_load_buttons_callbacks: ->
187187
@info('Build datatable callbacks options : buttons')
188188

189-
@callbacks['buttons']['select_all'] = { success: [(_data, _status, _xhr) => @datatable.ajax.reload()] }
190-
@callbacks['buttons']['reset_selection'] = { success: [(_data, _status, _xhr) => @datatable.ajax.reload()] }
189+
callback = (dt_class, _data, _status, _xhr) ->
190+
klass = Loader.class_methods.constantize(dt_class)
191+
klass.instance.datatable.ajax.reload()
192+
193+
@callbacks['buttons']['select_all'] = { success: [callback] }
194+
@callbacks['buttons']['reset_selection'] = { success: [callback] }
191195

192196

193197
_select: (obj, predicate) ->

src/modules/with_buttons.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ WithButtons.instance_methods =
114114

115115

116116
_build_ajax_options: (button) ->
117+
dt_class = @dt_class
117118
callbacks = @callbacks['buttons'][button]
118119
on_send = if callbacks.beforeSend? then callbacks.beforeSend else []
119120
on_error = if callbacks.error? then callbacks.error else []
@@ -122,13 +123,13 @@ WithButtons.instance_methods =
122123
{
123124
beforeSend: (xhr, settings) =>
124125
for c in on_send
125-
c(xhr, settings)
126+
c(dt_class, xhr, settings)
126127
error: (xhr, status, error) =>
127128
for c in on_error
128-
c(xhr, status, error)
129+
c(dt_class, xhr, status, error)
129130
success: (data, status, xhr) =>
130131
for c in on_success
131-
c(data, status, xhr)
132+
c(dt_class, data, status, xhr)
132133
}
133134

134135

0 commit comments

Comments
 (0)