Missing parameters (iDisplayStart, iDisplayLength etc)

Missing parameters (iDisplayStart, iDisplayLength etc)

anandsingh2000inanandsingh2000in Posts: 2Questions: 1Answers: 0

We are having a strange problem. We are using server side option of the datatable in a Spring application. The parameter in the controller are always null. Will greatly appreciate if someone can give a clue on why our controller does not receive these parameters.

  String sEcho = httpRequest.getParameter(S_ECHO);
  String sDisplayStart = httpRequest.getParameter(I_DISPLAY_START);
  String sDisplayLength = httpRequest.getParameter(I_DISPLAY_LENGTH);
  String sSortingCols = httpRequest.getParameter(I_SORTING_COLS);

Here is the usage of datatable:

    $('#myTable').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {"url": "<c:url value="/task/getTaskListAjax/" />",
                 "type": "POST"
        },
        "aoColumns" : [
                       {
                        "sTitle" : "Task ID",
                        "mData" : "taskId"
                       },
                       {
                        "sTitle" : "Task Name",
                        "mData" : "taskName"
                       },
                       {
                        "sTitle" : "Task Due Date",
                        "mData" : "taskDueDate"
                       },
                       {
                           "sTitle" : "Task Status",
                           "mData" : "taskStatus"
                       }
                     ]
    })
});

We are using following versions:

<%--Jquery--%>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

<%--Data Table--%>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>

<!-- Bootstrap core CSS -->
<link href="<c:url value="/resources/css/bootstrap.min.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/navbar.css" />" rel="stylesheet">

<link href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet">
 <script src="<c:url value="/resources/js/bootstrap.min.js" />"></script>

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    You are using some legacy terms on the latest version of DataTables. Try this:
    (also includes some features that can help with debugging)

           $('#myTable').DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {"url": "<c:url value="/task/getTaskListAjax/" />",
                    "type": "POST", 
                    "data":function(outData){
                        console.log(outData);
                        return outData;
                    },
                    dataFilter:function(inData){
                        console.log(inData);
                        return inData;
                    },
                    error:function(err, status){
                        console.log(err);
                    }
                },
                "columnDefs":[{targest:_all, orderable:true, searchable:true}],
                "columns" : [
                {
                    "title" : "Task ID",
                    "data" : "taskId",
                    "name":"taskId"
                },
                {
                    "title" : "Task Name",
                    "data" : "taskName",
                    "name": "taskName"
    
                },
                {
                    "title" : "Task Due Date",
                    "data" : "taskDueDate",
                    "name": "taskDueDate"
                },
                {
                    "title" : "Task Status",
                    "data" : "taskStatus",
                    "name":"taskStatus"
                }
                ]
            });
    
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    String sEcho = httpRequest.getParameter(S_ECHO); String sDisplayStart = httpRequest.getParameter(I_DISPLAY_START); String sDisplayLength = httpRequest.getParameter(I_DISPLAY_LENGTH); String sSortingCols = httpRequest.getParameter(I_SORTING_COLS);

    I don't know what your constants are defined as but from the DataTable above, I assume that these too are legacy. https://datatables.net/manual/server-side shows the terms you should be using

  • anandsingh2000inanandsingh2000in Posts: 2Questions: 1Answers: 0

    Hello bindrid, you are right. We had wrong parameter names. Instead of iDisplayLength, we should have used "length". Thank you so much for saving time for us.

  • Ankesh0601Ankesh0601 Posts: 9Questions: 0Answers: 0

    Hi Team, I am facing same issue now, means i am invoking iDisplayLength from Spring but not able getting numberFormatException : null

    Kindly help me with this issue

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Sounds like your server side processing script is expecting the SSP legacy parameters. If thats the case then you likely will need to use sAjaxSource instead of the DT 1.10 ajax option. This section of the SSP doc explains:
    https://datatables.net/manual/server-side#Legacy

    Kevin

  • Ankesh0601Ankesh0601 Posts: 9Questions: 0Answers: 0

    Hi Below is my data table code:
    table = $("#example").dataTable({

                                     "initComplete": initCompleteFunction,
    
                                    "bProcessing" : true,
    
                                    "bServerSide" : true,
    
                                    "sort" : "position",
    
                                    "bStateSave" : false,
    
                                    "iDisplayLength" : 10,
    
                                    "iDisplayStart" : 0,
    
                                    "sPaginationType": "full_numbers",
    
                                    "sAjaxSource" : "report",
    
                                    "aoColumns" : [{
    
                                        "mData" : "uniqueId"
    
                                    }, {
    
                                        "mData" : "rfpName"
    
                                    }, {
    
                                        "mData" : "dateName"
    
                                    }, {
    
                                        "mData" : "lataCs"
    
                                    }],
    
                                    "aoColumnDefs" : [{
    
                                        'bSortable' : false,
    
                                        'aTargets' : [ 0 ]
    
                                    }]
    
                                });
    
                $(".dataTables_empty").html("No data available");
    
            });
    

    And below is my spring action method :

    @RequestMapping(value = "/report", produces = "application/json" , method = RequestMethod.GET)
    public @ResponseBody String report(HttpServletRequest request) throws IOException  {
        System.out.println("Enter : main report" );
    
        Integer pageNumber = 0;
    
        if (null != request.getParameter("iDisplayStart"))
            pageNumber = (Integer.valueOf(request.getParameter("iDisplayStart")) / 10) + 1;
    
        String iDisplayStart = request.getParameter("iDisplayStart");
        String searchParameter = request.getParameter("sSearch");
        String sEcho = request.getParameter("sEcho");
    
        Integer pageDisplayLength = Integer.parseInt(request.getParameter("iDisplayLength"));
    
        System.out.println("pageNumber : "+pageNumber+" : pageDisplayLength : "+pageDisplayLength+" sEcho :"+sEcho);
    
        List<AllBidsBean> bean = listAllBids(Integer.parseInt(iDisplayStart), pageDisplayLength , searchParameter);
    
        int recordStart = (pageNumber - 1) * pageDisplayLength;
    
        int iDisplayPageStart = recordStart;
    
        System.out.println("iDisplayPageStart recordStart : "+iDisplayPageStart);
    
        DataTableObject dataTable = new DataTableObject();
        dataTable.setAaData(bean);
        dataTable.setiTotalDisplayRecords(bean.size());
        dataTable.setiTotalRecords(bean.size());
    
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String json = gson.toJson(dataTable);
        System.out.println("json : "+json.length());
    
        System.out.println("Exit : main report");
    
        return json;
    
    }
    

    Now i am not able to get the value of iDisplayLength and iDisplayStart in my action class i have tried both way using sAjaxResource and ajax both

  • Ankesh0601Ankesh0601 Posts: 9Questions: 0Answers: 0

    I am getting null value in idisplayLength and iDisplayStart, Kindly help me with solution.

  • Ankesh0601Ankesh0601 Posts: 9Questions: 0Answers: 0

    If I get the parameter in my action class using @RequestParam annotation of spring then it is showing below error in my browser :

    400 bad request : Required String parameter 'iDisplayStart' is not present

  • Ankesh0601Ankesh0601 Posts: 9Questions: 0Answers: 0

    Hi, In HttpServletRequest, i am not able to find anything, request is empty.

This discussion has been closed.