Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables server-side processing URL too long

Tags:

datatables

Is there a way I can stop it from sending all of the columns to the server?

Currently the AJAX request looks like:

ssp.php?draw=2&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D=&order%5B0%5D%5Bcolumn%5D=10&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1448240832750

But it's 5689 characters long. I'm looking for a way to disable all of the column data that isn't necessary. Is this possible?

like image 796
theshadow124 Avatar asked Nov 23 '15 01:11

theshadow124


1 Answers

if you use GET try to remove unnecessary column.

$('#your-table').DataTable({
  serverSide: true,
  processing: true,
  ajax: {
    url: 'url-here',
    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;
    }
  }
})
like image 152
Felix Avatar answered Sep 23 '22 12:09

Felix