Skip to content

Commit 351227d

Browse files
authored
Javascript improvements (#145)
* JS improvements * Remove scrollX * Allow config.options and config.url as functions * Remove empty line
1 parent 83c73b7 commit 351227d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Resources/public/js/datatables.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
return new Promise((fulfill, reject) => {
4444
// Perform initial load
45-
$.ajax(config.url, {
45+
$.ajax(typeof config.url === 'function' ? config.url(null) : config.url, {
4646
method: config.method,
4747
data: {
4848
_dt: config.name,
@@ -52,7 +52,7 @@
5252
var baseState;
5353

5454
// Merge all options from different sources together and add the Ajax loader
55-
var dtOpts = $.extend({}, data.options, config.options, options, persistOptions, {
55+
var dtOpts = $.extend({}, data.options, typeof config.options === 'function' ? {} : config.options, options, persistOptions, {
5656
ajax: function (request, drawCallback, settings) {
5757
if (data) {
5858
data.draw = request.draw;
@@ -71,7 +71,7 @@
7171
}
7272
} else {
7373
request._dt = config.name;
74-
$.ajax(config.url, {
74+
$.ajax(typeof config.url === 'function' ? config.url(dt) : config.url, {
7575
method: config.method,
7676
data: request
7777
}).done(function(data) {
@@ -81,6 +81,10 @@
8181
}
8282
});
8383

84+
if (typeof config.options === 'function') {
85+
dtOpts = config.options(dtOpts);
86+
}
87+
8488
root.html(data.template);
8589
dt = $('table', root).DataTable(dtOpts);
8690
if (config.state !== 'none') {

0 commit comments

Comments
 (0)