数据表动态隐藏/显示列太慢 [英] datatables dynamically hide/show column too slow

查看:87
本文介绍了数据表动态隐藏/显示列太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用数据表JQuery插件动态显示/隐藏列。当我有大约500行时,它需要永远这样做。我正在使用新的Datatables API 1.10.0。

My goal is to show/hide columns dynamically using datatables JQuery plugin. When I have around 500 rows it takes it forever to do it. I'm using new Datatables API 1.10.0.

$('#oats-detailed-view-button').click(function (e) {
                e.preventDefault();
                oatsTable.columns([6,7,8,9,10,11,12]).visible(true);
            });

有没有更有效的方法?

推荐答案

出现性能问题,我一般都会提出这些步骤:

Having performance issues, I suggest in general about these steps:


  1. 删除不必要数据

  2. 更改服务对象的选项

  3. 尝试以另一种方式使用服务对象

  4. 解决方法和调试服务对象(如果是开源的,即通知制作者有关调查结果)

  5. 同意生产者解决问题,或使用其他服务对象

  1. remove unnecessary data
  2. alter options of the service object
  3. try using the service object in another way
  4. Workaround and debugging the service object (if open source, i.e. inform the producer about findings)
  5. agree with the producer to solve the problem, or use another service object

到1:你确定你没有不必要的属性,关于你的单元格的文本和事件吗?

To 1: are you sure you have no unnecessary attributes, texts and events concerning your cells?

到2 :这是一个将 autoWidth 设置为false的提示,但在其他线程中没有帮助。 在jQuery DataTables中隐藏列的性能问题

To 2: here is a hint of setting autoWidth to false, but it didn't help in the other thread. Performance issues when hiding columns in jQuery DataTables

在DataTables API的选项中,还有一种影响性能的可能性: deferRender http://datatables.net/reference/option/deferRender - >您确定您的列仅显示吗?也许浏览器必须首先创建HTML,因为它在加载时没有创建?

In the options of DataTables API, there is one further possibility influencing performance: deferRender: http://datatables.net/reference/option/deferRender -> are you sure your columns are only made visible? Maybe the browser has to create the HTML first, as it was not created while loading?

此外,在DataTables手册/常见问题解答中,是对加速表的解释改变其构建方式: http://datatables.net/faqs/index (向下滚动到DataTables运行缓慢)。

Further, in the DataTables manual/FAQ is an explanation of speeding up the table by altering the way it's built: http://datatables.net/faqs/index (scroll down to "DataTables is running slow").

到3和4:我可以想到有两个html div 旁。 div 1包含列1到5, div 2包含列6到12.然后通过切换 div 2打开和关闭,所有的列将立即可见/不可见。我可以想象,如果你只使用 visibiliy:hidden display:none 浏览器不需要渲染新的。

To 3 and 4: I could think of having two html div containers seamlessly laying beside. div 1 contains columns 1 to 5, div2 contains columns 6 to 12. Then by switching div 2 on and off, all the columns would get visible/invisible at once. I could imagine that if you use only visibiliy:hidden and not display:none, the browser doesn't have to render new.

这篇关于数据表动态隐藏/显示列太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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