数据表使用新的ajax数据/发布请求重新初始化表

时间:2015-04-18 23:51:29

标签: jquery ajax jquery-datatables

我有一个带有一些复选框的数据表,当单击一个按钮时,我希望这些选中的行通过一个单独的查询运行,该查询返回一个JSON,其行将替换当前表中的行。使用1.10+ api如何使用新的ajax请求重绘表的内容?

目前这是我的按钮代码:

$('#compareRowButton').on('click', function() {
    var cells = dTable.cells( ).nodes();
    var post_ids = [];
    $.each(cells, function(i, e){ // iterate each row
    var checkbox = $(e).find('input.compareCheck'); // find the checkbox
    if(checkbox.is(':checked')) { // if this checkbox is checked
        var post_id = checkbox.attr('value'); // get the value
        post_ids.push(post_id); // push it inside the container
    }
    });
    if (post_ids.length > 0) {
        //dTable REINIT
        dTable.clear().draw();
        //end
    }
    });

清除表的行,但我需要在发送发布数据时使用新查询重新填充表(已检查行中复选框的值)

我正在思考dTable.clear()函数当前所处的内容(但尚未尝试过):

$.ajax({
          type : 'post',
           url : 'query/compare_baddebt.php', 
          data: {post_id: post_ids},
          dataType: "json",
       success : function(r)
           {
    dTable.clear();
    dTable.rows().add(r);
    dTable.draw();
$('#compareRowButton').hide();
$('#returnToResultsButton').show();
    }

任何数据表用户都可以告诉我这个代码理论上是否会正确地用新的行集填充我的表?

我主要是问这个问题,因为datatables网站上堆满了传统的api函数,我不知道在哪里区别于< 1.10和1.10 api调用,因为该网站是一个彻底的混乱。

0 个答案:

没有答案