如何从 HTML 源刷新/重新加载我的数据表 [英] How do I refresh/reload my DataTable from HTML source

查看:16
本文介绍了如何从 HTML 源刷新/重新加载我的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 BackboneJS 用多个数据源填充我的表.您无需了解 Backbone 即可协助回答此问题,因为该问题主要是 DataTables 问题.

I'm using BackboneJS to populate my table with multiple data sources. You do not need to know Backbone to assist in this question, as the issue is mainly a DataTables issue.

我在第一次呈现集合视图时初始化我的数据表.

I initialise my Datatable when the Collection View is rendered the first time.

我的问题是我不知道如何告诉 DataTables 如何在每个 ajax 请求之后从 DOM 重新加载它的数据.知道如何做到这一点吗?

My issue is that I don't know how to tell DataTables how to reload its data from the DOM after each ajax request. Any idea on how to do this?

另一个例子是为每一行加载一些数据,然后相应地更新它(由主干视图完成).但是我需要让 Datatables 知道 DOM 表发生了变化.

Another example is when loading some data for each row and then updating it accordingly (done by Backbone View). But I need to let Datatables know that the DOM table has changed.

更改表格的示例:

<table>
  <thead>...</thead>
  <tbody>
    <tr>
        <td>Some Data</td>
        <td>Some Data2</td>
        <td>Loading...</td>
    </tr>
    ...
  </tbody>
</table>

致:

<table>
  <thead>...</thead>
  <tbody>
    <tr>
        <td>Some Data</td>
        <td>Some Data2</td>
        <td data-order="5" data-search="5"><span class="some_classes">5</span></td>
   </tr>
      ...
  </tbody>
</table>

如有任何帮助,我们将不胜感激.

Any assistance would be greatly appreciated.

推荐答案

使用 rows().invalidate() 使所选行的 DataTables 中保存的数据无效.

Use rows().invalidate() to invalidate the data held in DataTables for the selected rows.

例如,使用原始数据源使所有行无效:

For example, to invalidate all rows using original data source:

var table = $('#example').DataTable();

table
    .rows()
    .invalidate()
    .draw();

请注意,draw() 会将表格重置为第一页.要保留页面,请改用 draw(false).

Please note that draw() will reset the table to the fist page. To preserve the page, use draw(false) instead.

这篇关于如何从 HTML 源刷新/重新加载我的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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