DataTables

【需求】:点击不同链接,使DataTables加载不同的数据,并定时拉取最新数据

本文适用  jquery.dataTables.min.js  版本: 1.9.4   ;其它几个js:

jquery-2.0.3.min.js

fnReloadAjax.js      下载

HTML

<a href="#" id="1" class="cluster">rmqdev-1</a>
<a href="#" id="2" class="cluster">rmqdev-2</a>

<table id="sample-table-2">
  <thead>
    <tr>
      <th>#</th>
      <th>Node name</th>
      <th>IP</th>
      <th>File descriptors</th>
      <th>Socket descriptors</th>
      <th>Erlang processes</th>
      <th>Memory</th>
      <th>Disk space</th>
    </tr>
  </thead>
</table>
JS
<script type="text/javascript">

    var table;

    $('.cluster').click(function () {
        var cluster_id = $(this).attr("id");
        listNode(cluster_id);
    });


    jQuery(function ($) {
        setInterval(function () {
            if ($.fn.dataTable.fnIsDataTable(document.getElementById('sample-table-2'))) {
                table.fnReloadAjax();
            }
        }, 3000);
    });

    function listNode(cluster_id) {
        if ($.fn.dataTable.fnIsDataTable(document.getElementById('sample-table-2'))) {
            table = $('#sample-table-2').DataTable();
            table.fnDestroy(false);
        }
        table = $('#sample-table-2').DataTable( {
            "bProcessing": true,
            "sAjaxSource": "/node/list?cluster_id=" + cluster_id
        } );
    }
</script>

后台返回JSON样例

{
  "aaData": [
    [
      "1",
      "xxx.com",
      "10.30.237.112",
      "2001",
      "1539",
      "30295",
      "2GB",
      "79GB"
    ],
    [
      "2",
      "yyy.com",
      "10.30.237.113",
      "667",
      "217",
      "15705",
      "2.5GB",
      "50GB"
    ],
    [
      "3",
      "zzz.com",
      "10.30.237.114",
      "655",
      "205",
      "17653",
      "3GB",
      "100GB"
    ]
  ]
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值