Skip to content

Commit

Permalink
Javascript improvements (#145)
Browse files Browse the repository at this point in the history
* JS improvements

* Remove scrollX

* Allow config.options and config.url as functions

* Remove empty line
  • Loading branch information
danut007ro authored Apr 2, 2020
1 parent 83c73b7 commit 351227d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Resources/public/js/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

return new Promise((fulfill, reject) => {
// Perform initial load
$.ajax(config.url, {
$.ajax(typeof config.url === 'function' ? config.url(null) : config.url, {
method: config.method,
data: {
_dt: config.name,
Expand All @@ -52,7 +52,7 @@
var baseState;

// Merge all options from different sources together and add the Ajax loader
var dtOpts = $.extend({}, data.options, config.options, options, persistOptions, {
var dtOpts = $.extend({}, data.options, typeof config.options === 'function' ? {} : config.options, options, persistOptions, {
ajax: function (request, drawCallback, settings) {
if (data) {
data.draw = request.draw;
Expand All @@ -71,7 +71,7 @@
}
} else {
request._dt = config.name;
$.ajax(config.url, {
$.ajax(typeof config.url === 'function' ? config.url(dt) : config.url, {
method: config.method,
data: request
}).done(function(data) {
Expand All @@ -81,6 +81,10 @@
}
});

if (typeof config.options === 'function') {
dtOpts = config.options(dtOpts);
}

root.html(data.template);
dt = $('table', root).DataTable(dtOpts);
if (config.state !== 'none') {
Expand Down

0 comments on commit 351227d

Please sign in to comment.