DataTables and Long URL


Minify dataTables generated url by deleting unnecessary parameters.

DataTables and Long URL

Minify dataTables generated url by deleting unnecessary parameters.


It's been a long issue of laravel-datatables on dealing with long url being generated by DataTables. And thanks to @isometriq's investigation, I finally figured out a way to work around on this issue. The solution is to simply remove any unnecessary url query string parameters that are needed when processing our table. Luckily, DataTables provides us with an eloquent way of doing this via it's ajax option. 

Coding Time

Below is the code for our shorter dataTables url. The only thing we need to update is the ajax options.


$('#my-table').DataTable({
  serverSide: true,
  processing: true,
  ajax: {
    url: '',
    data: function (data) {
      for (var i = 0, len = data.columns.length; i < len; i++) {
        if (! data.columns[i].search.value) delete data.columns[i].search;
        if (data.columns[i].searchable === true) delete data.columns[i].searchable;
        if (data.columns[i].orderable === true) delete data.columns[i].orderable;
        if (data.columns[i].data === data.columns[i].name) delete data.columns[i].name;
      }
      delete data.search.regex;
    }
  }
})

First, we remove column.search parameters if it's not set.

Second, we remove searchable parameter since it's true by default.

Third, we remove oderable parameter since it's also true by default.

Fourth, we remove name if it's equal to data since our server-side handler falls back to data if name is not provided.

Lastly, we remove search.regex since it's not really used at all.


  • Laravel
  • Tips And Tricks
  • Datatables