jquery数据表 - 服务器端处理无法正常工作 [英] jquery data tables - Server-side processing not working as expected

查看:120
本文介绍了jquery数据表 - 服务器端处理无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON对象,我从一个php文件收到,JSON对象是按照指定的格式创建的。但是我得到
的警告UNRESPONSIVE SCRIPT.I已有超过50,000条记录,它加载每个记录,而不是我在iDisplayLength参数中指定的20条记录。
我知道我做错了,请帮忙。



JSON对象:

  {
iTotalRecords:52000,
iTotalDisplayRecords:52000,
sEcho:0,
aaData [
{itemID:13901,itemName:Item 1,itemModel:Model 1,Price:20},
{itemID 13902,itemName:Item 2,itemModel:Model 2,Price:30},
{itemID:13903,itemName 3,itemModel:Model 3,Price:50},
{itemID:13904,itemName:Item 4,itemModel ,Price:60},
{itemID:13905,itemName:Item 5,itemModel:Model 5,Price:20 ,
................
]
}

$(document).ready(function(){
$('#tbItems')。dataTable({
bProcessing:true,
bServerSide:true,
sAjaxSource:getItems,
aoCo列:
{sTitle:itemID,mDataProp:itemID},
{sTitle:itemName,mDataProp:itemName},
{sTitle:itemModel,mDataProp:itemModel},
{sTitle:itemPrice,mDataProp:itemPrice}
],
sPaginationType:full_numbers,
bLengthChange:false,
iDisplayLength:20,
aaSorting:[[1,asc]]
});
});


解决方案

服务器只能通过一定量的数据一个请求。



基本上,什么数据表正在做,即使你定义了一个显示参数,它仍然会从您的来源,然后处理它。



数据库提取数据,然后处理所有内容并将其放在内部数组中。我只能想象一下,在几百行之后,它会占用多少空间。



无论如何, bServerSide boolean通知您要处理的数据,并自动处理所有内容,然后反馈所需的内容。您应该阅读 datatables.net 上的文档和示例。



您应该密切关注服务器端的处理方式,因为它适合您的场景,您有一个巨大的数据集可以使用。





最后一个显示了如何管理大型数据集以及如何进行分页的完整参考,以及服务器端的所有内容,有效节省了处理负载您的问题是,您返回的所有内容,但忘记过滤数据,只包括当前页面上的行。这一切都在服务器端上完成,因此变量名称。


I have got a JSON object that I receive from a php file,the JSON object is created as per the specified format.But I get the the warning UNRESPONSIVE SCRIPT.I have got over 50,000 records and it loads every record instead of the 20 records I specified in the iDisplayLength parameter. I know Im doing something wrong,please help.

The JSON Object :

{
    "iTotalRecords":"52000",
    "iTotalDisplayRecords":"52000",
    "sEcho":0,
    "aaData":[
        {"itemID":"13901","itemName":"Item 1","itemModel":"Model 1","Price":"20"},
        {"itemID":"13902","itemName":"Item 2","itemModel":"Model 2","Price":"30"},
        {"itemID":"13903","itemName":"Item 3","itemModel":"Model 3","Price":"50"},
        {"itemID":"13904","itemName":"Item 4","itemModel":"Model 4","Price":"60"},
        {"itemID":"13905","itemName":"Item 5","itemModel":"Model 5","Price":"20"},
        ................
    ]
}    

$(document).ready( function () {
        $('#tbItems').dataTable( {
                        "bProcessing": true,
                        "bServerSide": true,
                        "sAjaxSource": "getItems",
                        "aoColumns": [
                          { "sTitle": "itemID",  "mDataProp": "itemID" },
                          { "sTitle": "itemName",  "mDataProp": "itemName" },
                          { "sTitle": "itemModel", "mDataProp": "itemModel" },
                          { "sTitle": "itemPrice",  "mDataProp": "itemPrice" }
                        ],
                        "sPaginationType": "full_numbers",
                        "bLengthChange": false,
                        "iDisplayLength": 20,
                        "aaSorting": [[ 1, "asc" ]]
        });
    });

解决方案

The server can only pass a certain amount of data through a request.

Essentially, what datatables is doing, is, even though you define a display parameter, it will still fetch all the data from your source and then process it.

Datatables fetches the data and then processes everything and puts it in an internal array. I can only imagine how much space it would take up after only a couple of hundred rows.

In any case, the bServerSide boolean notifies datatables that you're going to handle and process everything yourself and then feed back what you want. You should read up on the documentation and examples available at datatables.net.

You should pay close attention to how they do the server side processing since it is perfect for your scenario where you have a huge dataset to work with.

The last one shows a complete reference to how to manage large datasets and how to do the paging, and pretty much everything, on the server side, effectively saving up loads of processing time for datatables.

Your problem is that you're returning everything but forgetting to filter the data to only include the rows on the current "page". This is all done on the server-side, hence the variable name.

这篇关于jquery数据表 - 服务器端处理无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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