代码之家  ›  专栏  ›  技术社区  ›  yer

角度4:数据表加载大数据需要时间

  •  0
  • yer  · 技术社区  · 8 年前

    我有一个datatable,它花费了很多时间来显示数据

    我在组件中这样调用脚本:

      ngAfterViewInit() {
        $.getScript('./assets/js/datatables/datatable-basic.js');
      }
    

    以html格式呈现数据,如下所示

    <table class="table zero-configuration">
        <thead>
            <tr>
              <th>Name</th>
              <th>ID</th>
              <th></th>
            </tr>
         </thead>
         <tbody>
            <tr *ngFor="let companyData of company?.companies; trackBy: userThumb">
                <td class="text-truncate">{{ companyData?.name }}</td>
                <td class="text-truncate">{{companyData?.id}}</td>
                <td class="text-truncate"></td>
            </tr>
         </tbody>
        </table>
    

    这是我的datatable basic。js公司

    setTimeout(function () {
        $('.zero-configuration').DataTable({
          "iDisplayLength": 50,
          "paging": true
        });
    }, 3000);
    

    这些公司将拥有近5000个阵列。

    1 回复  |  直到 8 年前
        1
  •  1
  •   GreyBeardedGeek    8 年前

    似乎您已经在客户端“设置了分页”-您仍在通过网络加载5K条记录,但一次只显示50条。要真正影响性能,您可能必须进行服务器端分页,以便一次只加载50条记录。

    编辑:以下是一个示例: How to use server side option in Angular DataTables with the Angular way example?