【问题标题】:datatables 1.10 add.row() not working within ajax responsedatatables 1.10 add.row() 在 ajax 响应中不起作用
【发布时间】:2014-06-06 07:25:08
【问题描述】:

使用带有 dom 创建表的数据表 1.10。我正在尝试在 ajax 响应中添加新的数据行,但没有任何反应。相同的代码本身(没有 ajax)工作得非常好。是的,response.success 正在返回“true”。

// 这工作并将新行添加到表中

$('#test').on('click', function () {
    dt.row.add( [
        'td0',
        'td1',
        'td2',
        'td3'
    ] ).draw();
});

//相同的代码在 ajax 响应中不起作用...

$('#dtCreate').on('click', function () {

    $.ajax({
        type: 'post',
        url: '/test/process/p_db_create.php'
    }).done(function (response) {

        //double check response
        console.log(response);

        if (response.success)
        {
            //add the row since this is not serverside
            dt.row.add( [
                'td0',
                'td1',
                'td2',
                'td3'
            ] ).draw();
                ...more code below...

【问题讨论】:

  • 你有没有找到解决这个问题的方法?我遇到了同样的问题。

标签: jquery ajax datatables jquery-datatables


【解决方案1】:

td 应该由 DataTable() 而不是 dataTable() 启动。我遇到了这个问题,浪费了我好几个小时。

【讨论】:

    【解决方案2】:

    在你调用 add().draw(); 之后通过调用--重新初始化表 dt.dataTable();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      相关资源
      最近更新 更多