dataTables生成多个服务器端请求 [英] dataTables generating multiple server side requests

查看:133
本文介绍了dataTables生成多个服务器端请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dataTable jquery插件,启用服务器端处理。在使用 fnReloadAjax 函数时,在处理div隐藏和显示新数据之间有2-3秒的延迟。以下是有关此问题的帖子
我发现这是由于datatable产生的多个服务器请求。



在我的页面中 onchange 一组单选按钮的事件正在调用服务器获取新数据,如下所示

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

在firebug控制台中,我看到一个接一个地进行了两个请求。


  1. GET https:// localhost / getCaseList?caseStatus = xxx& showValidOnly = true& _ = 1363611652185 li>
  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

处理div在第一个请求完成后变得隐藏,但是仅在第二个请求完成后加载新数据。 p>

为什么datatable进行第二次额外的调用?

解决方案

遇到同样的问题。在我的情况下,我一直在使用服务器端处理。
在datatable初始化之后,我写了下面的语句来隐藏一些列

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

我意识到这是请求4次。
然后我删除了这些行,多个请求的问题在我的情况下解决了。
如果你还想隐藏列,还有一种方法是添加一个类('sClass':'hidden'),它将display:none设置为datatable的列定义中的列。 / p>

  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隐藏},
{bSortable:true,aTargets:[6],sClass:hidden},
{bSortable:false,aTargets },
{bSortable:false,aTargets:[8]},
{bSortable:false,aTargets:[9],sClass:hidden}

]

希望这有帮助。
谢谢


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?

解决方案

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

这篇关于dataTables生成多个服务器端请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆