Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit d573e35

Browse files
committed
Correct buttons for ng renderer #502
1 parent bbb0867 commit d573e35

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

dist/plugins/buttons/angular-datatables.buttons.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
1212

1313
// See https://datatables.net/extensions/buttons/
1414
angular.module('datatables.buttons', ['datatables'])
15-
.config(dtButtonsConfig);
15+
.config(dtButtonsConfig)
16+
.run(initButtonsPlugin);
1617

1718
/* @ngInject */
1819
function dtButtonsConfig($provide, DT_DEFAULT_OPTIONS) {
@@ -63,5 +64,32 @@ function dtButtonsConfig($provide, DT_DEFAULT_OPTIONS) {
6364
}
6465
dtButtonsConfig.$inject = ['$provide', 'DT_DEFAULT_OPTIONS'];
6566

67+
/* @ngInject */
68+
function initButtonsPlugin(DTRendererService) {
69+
var buttonsPlugin = {
70+
preRender: preRender,
71+
postRender: postRender
72+
};
73+
DTRendererService.registerPlugin(buttonsPlugin);
74+
75+
function preRender(options) {
76+
if (angular.isArray(options.buttons)) {
77+
// The extension buttons seems to clear the content of the options.buttons for some reasons...
78+
// So, we save it in a tmp variable so that we can restore it afterwards
79+
// See https://github.com/l-lin/angular-datatables/issues/502
80+
options.buttonsTmp = options.buttons.slice();
81+
}
82+
}
83+
84+
function postRender(options) {
85+
if (angular.isDefined(options.buttonsTmp)) {
86+
// Restore the buttons options
87+
options.buttons = options.buttonsTmp;
88+
delete options.buttonsTmp;
89+
}
90+
}
91+
}
92+
initButtonsPlugin.$inject = ['DTRendererService'];
93+
6694

6795
})(window, document, jQuery, angular);

dist/plugins/buttons/angular-datatables.buttons.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/buttons/angular-datatables.buttons.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
// See https://datatables.net/extensions/buttons/
44
angular.module('datatables.buttons', ['datatables'])
5-
.config(dtButtonsConfig);
5+
.config(dtButtonsConfig)
6+
.run(initButtonsPlugin);
67

78
/* @ngInject */
89
function dtButtonsConfig($provide, DT_DEFAULT_OPTIONS) {
@@ -50,3 +51,29 @@ function dtButtonsConfig($provide, DT_DEFAULT_OPTIONS) {
5051
}
5152
}
5253
}
54+
55+
/* @ngInject */
56+
function initButtonsPlugin(DTRendererService) {
57+
var buttonsPlugin = {
58+
preRender: preRender,
59+
postRender: postRender
60+
};
61+
DTRendererService.registerPlugin(buttonsPlugin);
62+
63+
function preRender(options) {
64+
if (angular.isArray(options.buttons)) {
65+
// The extension buttons seems to clear the content of the options.buttons for some reasons...
66+
// So, we save it in a tmp variable so that we can restore it afterwards
67+
// See https://github.com/l-lin/angular-datatables/issues/502
68+
options.buttonsTmp = options.buttons.slice();
69+
}
70+
}
71+
72+
function postRender(options) {
73+
if (angular.isDefined(options.buttonsTmp)) {
74+
// Restore the buttons options
75+
options.buttons = options.buttonsTmp;
76+
delete options.buttonsTmp;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)