srk
srk

Reputation: 5126

jQuery DataTables server-side processing with Java

I am looking for how to implement jQuery DataTables with server-side processing in Java. I have tried the following way by using the below parameters. Below is my jQuery ready function code.

$(document).ready(function() {
    //url = http://localhost:8080/jQuery-DataTable-Java-Integration/serverExample
    $('#myTableId').DataTable({
        "serverSide" : true,
        "processing" : true,
        /*"bProcessing" : true,
        "bServerSide" : true,*/
        "ajax" : {
            "url" : "serverExample",
            "type" : "POST"
        },
        "columns" : [ {
            "data" : "Phone Number"
        }, {
            "data" : "name"
        }, {
            "data" : "Email"
        } ]
    });
});

In my servlet doPost() method I the request parameter sEcho is null.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        logger.info("In do post method of server servlet..");
        logger.info("sEcho request parameter = " + request.getParameter("sEcho"));//returning null
//other code here
}

My jQuery DataTables version is 1.10.7. Which parameters should be used, serverSide or bServerside, I tried both ways, but still the same. Any latest updated working example references would be helpful.

Upvotes: 1

Views: 7175

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58860

When using DataTables 1.10 version in server-side processing mode, client side sends draw parameter along with other parameters. Full list is shown on DataTables website.

Previous version of DataTables 1.9 used sEcho parameter in server-side processing mode, see documentation for more information.

If you have server-side script written for DataTables 1.9, it is possible to force DataTables 1.10 to send parameters compatible with previous version. Below is an excerpt from the manual:

Older versions of DataTables (1.9-) used a different set of parameters to send and receive from the server. As such scripts which are written for DataTables 1.10+ will not be able to function with DataTables 1.9-. However, DataTables 1.10 does have a compatibility mode for scripts written for 1.9-. This compatibility mode is triggered by use of the old sAjaxSource parameter (rather than the new ajax parameter) or by setting$.fn.dataTable.ext.legacy.ajax = true; .

You should be using serverSide and processing which are preferred option names for version 1.10 although it accepts option names (bServerSide and bProcessing) for previous version as well.

Upvotes: 4

Related Questions