简体   繁体   English

DataTable:如何加快页面加载?

[英]DataTable : How to make a page load faster?

I have about 20,000 rows in my database, and I use DataTable to load all of those data. 我的数据库中有大约20,000行,我使用DataTable加载所有这些数据。

  • DataTable is loading all of my data at the beginning. DataTable在开始时加载我的所有数据。
  • DataTable works fine with a small amount of data like 100 or below, but in my case, my page took about 3 minutes to load a page. DataTable适用于少量数据,如100或更低,但在我的情况下,我的页面花了大约3分钟来加载页面。 Very Bad ! 很坏 !

What is the most efficient way to improve the loading speed using DataTable ? 使用DataTable提高加载速度的最有效方法是什么?


Update: 更新:

Here is my table 这是我的桌子

<table id="inventory_exact"> ...

Here is my setting to it 这是我的设定

  // Setting to Inventory Table 
  $('#inventory_exact').dataTable({

    "lengthMenu": [ 10 ] ,
    "bLengthChange": false,
    "searchHighlight": true,
    "bInfo" : false

  });

Update 2: - server side 更新2: - 服务器端

@niyou : I use PHP Laravel , so I query my data and display them by doing this @niyou:我使用PHP Laravel,所以我查询我的数据并通过这样做来显示它们

            @foreach ( Inventory::all() as $inventory)
             <tr>
                <td>{{ $inventory->sku }} </td>
                <td>{{ $inventory->description }} </td>
                <td>${{ $inventory->price }} </td>
                <td>{{ $inventory->stock }} </td>
             </tr>
            @endforeach

When you are dealing with client-side large datasets (by large i define as over 1000) , you would probably want to switch to the Server-side implementation of data for your datatables data 当您处理客户端大型数据集(大型定义为超过1000)时,您可能希望切换到数据表数据的服务器端数据实现

Using the newest 1.10 syntax it would look like this 使用最新的1.10语法,它看起来像这样

table = $('#example').DataTable( {
    serverSide: true,
    ajax: {
      url:"index.cfm/observers/json",
      },
  });

where the url returns a json object that has draw, totalrecordcount, totalfilteredcount, and data url返回具有draw,totalrecordcount,totalfilteredcount和data的json对象

I have included links to documentation for 我已经包含了文档的链接

Datatables Server-Side Documentation 数据表服务器端文档

PHP example script to generate JSON needed for datatables on Github using SSP.class PHP示例脚本,使用SSP.class为Github上的数据表生成所需的JSON

PHP script to generate JSON for datatables written spagetti style (if you cant use SSP or need to use older datatables) 用于为spagetti样式的数据表生成JSON的PHP脚本(如果您不能使用SSP或需要使用旧的数据表)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM