php jQuery 数据表插件太慢 - 需要更换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11646377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery datatables plugin too slow - need a replacement
提问by Nikola
I've been using jQuery datatables pluginfor about two years now and it worked great so far. The problem occured now when I need to load about 45000records at once (you click the button and wait for the page with the data to load) - the loading time is just too big to wait.
我已经使用 jQuery 数据表插件大约两年了,到目前为止效果很好。现在当我需要一次加载大约45000条记录时出现问题(您单击按钮并等待加载数据的页面) - 加载时间太长而无法等待。
Here are the tests I made using Chrome web browser (the data is from it's Network tab using ):
以下是我使用 Chrome 网络浏览器进行的测试(数据来自使用 的网络选项卡):
datatables plugin turned on:
5476records:24 requests ? 256.26KB transferred ? 19.80s
(onload: 19.80s, DOMContentLoaded: 18.58s)
45071records:34 requests ? 1.85MB transferred ? 11.1min
(onload: 11.1min, DOMContentLoaded: 11.0min)
数据表插件打开:
5476条记录:45071条记录:24 requests ? 256.26KB transferred ? 19.80s
(onload: 19.80s, DOMContentLoaded: 18.58s)34 requests ? 1.85MB transferred ? 11.1min
(onload: 11.1min, DOMContentLoaded: 11.0min)
datatables plugin turned off (the jQuery datatables initialization is comented out):
5476records:21 requests ? 255.84KB transferred ? 6.57s
(onload: 13.26s, DOMContentLoaded: 13.28s)
数据表插件关闭(jQuery数据表初始化被注释掉):
5476条记录:21 requests ? 255.84KB transferred ? 6.57s
(onload: 13.26s, DOMContentLoaded: 13.28s)
45071records:31 requests ? 1.84MB transferred ? 2.0min
(onload: 2.0min, DOMContentLoaded: 2.0min)
45071条记录:31 requests ? 1.84MB transferred ? 2.0min
(onload: 2.0min, DOMContentLoaded: 2.0min)
The increase in load timethat datatables make is over 80%for the 45k rows, and almost 40%for the 5k rows.
数据表使45k 行的加载时间增加了80%以上,5k 行增加了近40%。
So I was wondering if you guys know of any similar plugin that handles alot of rows (45000+) faster, or am I just missing the point by trying to load all 45000+ records in "one go"?
所以我想知道你们是否知道任何类似的插件可以更快地处理很多行(45000+),或者我只是通过尝试“一次性”加载所有 45000+ 记录而错过了重点?
Any suggestions are appreciated!
任何建议表示赞赏!
回答by Allan Jardine
From the DataTables FAQs ( http://datatables.net/faqs#speed):
来自 DataTables 常见问题解答 ( http://datatables.net/faqs#speed):
- Client-side processing - DOM sourced data: ~5'000 rows. Speed options: bSortClasses
- Client-side processing - Ajax sourced data: ~50'000 rows. Speed options: bDeferRender
- Server-side processing: millions of rows.
- 客户端处理 - DOM 源数据:约 5'000 行。速度选项:bSortClasses
- 客户端处理 - Ajax 源数据:约 50'000 行。速度选项:bDeferRender
- 服务器端处理:数百万行。
If you aren't using deferred rendering at the moment, with your 45'000 rows, I would most certainly suggest that. Failing that, for DataTables options, you might need to look at server-side processing.
如果您目前不使用延迟渲染,有 45,000 行,我肯定会建议您这样做。否则,对于 DataTables 选项,您可能需要查看server-side processing。
回答by user1477388
The answer by Allan is good; but one other thing to mention (which greatly effects the loading time) is setting bProcessingand bServerSideto true as shown in the code below:
艾伦的回答很好;但要提到的另一件事(这会极大地影响加载时间)是设置bProcessing并设置bServerSide为 true,如下面的代码所示:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php"
} );
} );
Ref. http://datatables.net/examples/data_sources/server_side.html
参考 http://datatables.net/examples/data_sources/server_side.html
My code was taking 15 seconds to load, now it takes like 1 second :)
我的代码加载需要 15 秒,现在需要 1 秒 :)
回答by Peter G.
I found that browser plugins can also slow the performance of the DataTable down, which was in my case. The loading time for the table itself went from about 15s to 2s.
我发现浏览器插件也会降低 DataTable 的性能,这就是我的情况。表本身的加载时间从大约 15 秒变为 2 秒。
One of them is Skype Toolbar, which automatically parses data in the table, unless you tell it not to.
其中之一是Skype Toolbar,它会自动解析表中的数据,除非您告诉它不要这样做。
This is a problem for huge tables. Lot of users have that plugin and it unknowingly slows their loading of large tables.
这对于大表来说是一个问题。很多用户都有这个插件,它在不知不觉中减慢了他们对大表的加载。
There is one good solution for this, add this to the header. Every DataTables web page that goes to the public should contain this:
对此有一个很好的解决方案,将其添加到标题中。每个公开的 DataTables 网页都应该包含以下内容:
<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />

