dataTables generating multiple server side request

2019-07-26 01:29发布

I am using dataTable jquery plugin with server side processing enabled. While using fnReloadAjax function, there is a delay of 2-3 seconds between hiding of the processing div and display of the new data. Here is a post regarding this problem. I found out that this is due to multiple server requests made by datatable.

In my page onchange event of a set of radio buttons is making a call to server for new data as follows

oTable.fnReloadAjax("getCaseList?caseStatus=xxx&showValidOnly=true");

In the firebug console I see two requests being made one after the other

  1. GET https://localhost/getCaseList?caseStatus=xxx&showValidOnly=true&_=1363611652185
  2. GET https://localhost/getCaseList?caseStatus=xxx&showValidOnly=true&sEcho=4&iColumns=9&sColumns=&iDisplayStart=0&iDisplayLength=100&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&sSearch_8=&bRegex_8=false&bSearchable_8=true&iSortingCols=1&iSortCol_0=4&sSortDir_0=desc&bSortable_0=false&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=true&bSortable_8=true&_=1363611701804

The processing div is getting hidden after the completion of first request but new data is loaded only after the second request is complete.

Why is datatable making that second extra call?

2条回答
干净又极端
2楼-- · 2019-07-26 02:07

Server side requests are issued by the internal _fnAjaxUpdate function, which is called from _fnDraw.

This means you are probably calling some method that needs to redraw the table, like a sort or a search, which issues that additional request.

查看更多
可以哭但决不认输i
3楼-- · 2019-07-26 02:08

I have been running into the same problem. In my case also i have been using server side processing. After the datatable was initialized, I had written the below statements to hide some columns

tableExample.fnSetColumnVis(5, false);
tableExample.fnSetColumnVis(6, false);
tableExample.fnSetColumnVis(3, false);

And I realized it was requesting 4 times. Then I removed these lines and the the problem of multiple request was solved in my case. How ever if you want to still hide the columns, there is another approach by adding a class ('sClass':'hidden') which sets "display:none" to the column in the column definition of datatable.

  aoColumnDefs: [
        { "bSortable": true, "aTargets": [0] },
        { "bSortable": true, "aTargets": [1] },
        { "bSortable": false, "aTargets": [2] },
        { "bSortable": true, "aTargets": [3] },
        { "bSortable": true, "aTargets": [4] },
       { "bSortable": true, "aTargets": [5], "sClass": "hidden" },
        { "bSortable": true, "aTargets": [6], "sClass": "hidden" },
        { "bSortable": false, "aTargets": [7] },
        { "bSortable": false, "aTargets": [8] },
        { "bSortable": false, "aTargets": [9], "sClass": "hidden" }         

      ]

Hope this helps. Thanks

查看更多
登录 后发表回答