jQuery DataTables-启动缓慢,“正常"开头显示的html表 [英] jQuery DataTables - Slow initiation, "Normal" html table shown in the beginning

查看:104
本文介绍了jQuery DataTables-启动缓慢,“正常"开头显示的html表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery DataTable插件,但我担心脚本加载似乎需要一些时间,因此我的网页始终始终首先显示普通的html表,并且在完成所有脚本后,该表将变为数据表. 我认为这种外观是不可接受的,因此我希望可以在这里获得一些建议.我是否可以使脚本更快,还是不在前面显示普通表? 顺便说一句,我正在_Layout.cshtml头标记的_Scripts部分视图中调用脚本

I'm using jQuery DataTable plugin, but I got a concern where the scripts loading seems to take some time, so my web page is always displaying the ordinary html table first, and after all script done, the table will then become DataTable. I don't think this kind of appearance is acceptable, so I hope can get some advices here. whether I can make the scripts faster, or don't display the plain table ahead? Btw, I am calling my script from a _Scripts partial view at my _Layout.cshtml head tag

 @Html.Partial("_Scripts") 

(更新) 我试图隐藏表,并在数据表初始化后显示它,但是,我得到了没有表头的数据表.知道为什么会这样吗?

(UPDATE) I tried to hide the table, and show it after the datatable initialize, however, I get a datatable without the table header. Any idea why this is happening?

$('#stocktable').hide();
// Initialize data table
    var myTable = $('#stocktable').dataTable({

        // Try styling
        "sScrollX": "100%",
        "sScrollXInner": "100%",
        "bScrollCollapse": true,

        // To use themeroller theme
        "bJQueryUI": true,
        // To use TableTool plugin
        "sDom": 'T<"clear">lfrtip',
        // Allow single row to be selected
        "oTableTools": {
            "sRowSelect": "single"
        },
        "fnInitComplete": function () {
            $('#stocktable').show();
        }

推荐答案

原始答案如下:

我需要说明的是,我不熟悉_Scripts部分视图,因此下面的建议是我给人们提供的只是以正常"方式包含和调用JavaScript的内容:

My caveat is that I am not familiar with _Scripts partial views, so the advice below is what I would give someone just including and calling JavaScript in the 'normal' ways:

  1. 设置纯HTML表格的样式,使其具有与最终外观相同的外观.如果您启用了jQuery UI(bJQueryUI: true),则意味着在普通"表中具有jQuery UI类,而不是等待DT添加它们.

  1. Style the plain HTML table so that it shares the same appearance as the final. If you have jQuery UI enabled (bJQueryUI: true), this means having the jQuery UI classes in the 'plain' table rather than waiting for DT to add them.

使用各种FOUC(无样式内容的闪烁)技术隐藏表格,直到准备好进行渲染为止. DataTables API具有有用的回调,您可以将其用于事物的立即显示"部分,例如fnInitCallback.最基本(但会损坏可访问性)的技术是使用display:none设置表的样式,然后在回调中使用$('#myTable').show()或某些变体.在互联网上搜索应该提供一些很好的解决方案,以保持可访问性.

Use various FOUC (flash of unstyled content) techniques to hide the table until it is ready to render. DataTables API has useful callbacks that you can use for the "show it now" part of things, such as fnInitCallback. The most basic (but accessibility-damaging) technique is to style the table with display:none, and in the callback, use $('#myTable').show() or some variation. Searching on the internet should provide some great solutions that preserve accessibility.

除此之外,它实际上只是(如您所说!)对可接受"的容忍度的问题.我们使用服务器端处理(返回的记录少得多),脚本加载器以加快脚本加载时间(我们正在尝试使用head.js,但还有其他功能!),以及脚本的最小化版本.即便如此,我们有时仍会在普通表变成DT之前看到它一会儿,但是由于互联网用户习惯于在元素加载之前看到页面是在构建"的,因此这是一个可以接受的折衷方案.对于您来说,可能不是.

Other than that, it's really just a question of (as you say!) tolerance for "acceptable". We use server-side processing (returning far fewer records), a script loader for faster script loading time (we're experimenting with head.js but there are others!), and the minimized versions of the scripts. Even with this, we sometimes see the plain table for a moment before it becomes a DT, but since internet users are accustomed to seeing pages being 'built' before their eyes as elements are loaded, it was an acceptable tradeoff. For you, it might not be.

祝你好运!

这篇关于jQuery DataTables-启动缓慢,“正常"开头显示的html表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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