10
votes

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?

5

5 Answers

17
votes

You can send it via POST instead, so none of those fields will appear on the URL sent to your server. Here's an example from the docs:

$(document).ready(function() {
    $('#example').DataTable( {
        "serverSide": true,
        "ajax": {
            "url": "scripts/post.php",
            "type": "POST"
        },
    };
});
9
votes

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;
    }
  }
})
5
votes

use can suppress unnecessary parameters like way bellow:

"ajax":{
        url :"admin/customers/ajax_datatables",
        type: "get",
        data: function ( data) {
            delete data.columns; // <-- too long and not neccessary if you don't use

            //and you can add more data
            data.form_search_params = $("#frm_search").serializeFormJSON();
        },
        error: function (xhr, error, thrown) {
            console.log(xhr);
        }
    },
2
votes

Use delete to remove the fields you don't want to send. Eg below:

"ajax": {
            "url": "yoururl",
            "data": function (d) {
                for (var i = 0, len = data.columns.length; i < len; i++) {
                    delete data.columns[i];
                }
                delete data.search.regex;
                return $.extend({}, d, {
                    "filterOne": $('#mydropdown').val(),
                });

            },
            "type": "GET",
        },