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

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

问题描述

我正在使用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?

另一个示例是为每行加载一些数据,然后进行相应更新(通过Backbone View完成).但是我需要让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.

将表格从以下位置更改的示例:

Example changing the table from:

<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>

任何帮助将不胜感激.

推荐答案

使用

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源刷新/重新加载DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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