DataTables row()。remove()调用未响应

时间:2019-07-02 20:14:55

标签: javascript jquery datatables

我有一个从服务器端(带有ajax管道)运行的DataTable。显示屏正常,工作正常。在表格的最后一列中,有一个按钮,单击该按钮将删除相应的行。此功能失败。

我还用https://datatables.net/examples/api/select_single_row.html中所述的表格外部的单个删除按钮进行了测试,但这也不起作用。仅在这种情况下才取消选择选定的行。

要点

  • onclick事件中的Javascript警报正在起作用
  • tr 标签已正确获取
  • table.row()。remove()。draw()不起作用

示例表格数据:

<tbody>
<tr role="row" class="odd">
    <td>1</td>
    <td>গীতগোবিন্দ</td>
    <td>Jaydev Goswami</td>
    <td>1100</td>
    <td><textarea class="senedtxt rdonly" onfocus="javascript: save_sentence(this, 26869, 13, false);" onblur="javascript: save_sentence(this, 26869, 13, true);">করেন যতন মোর রাখিবারে মন, তাঁহার সে খেলা কলি-কলুষ-নাশন</textarea></td>
    <td><button class="jqbtn" onclick="javascript: return delocc(this,1);">delete</button></td>
</tr>
<tr role="row" class="even">
    <td>2</td>
    <td>তিতাস একটি নদীর নাম</td>
    <td>Adwaita Mallabarman</td>
    <td>1930</td>
    <td><textarea class="senedtxt rdonly" onfocus="javascript: save_sentence(this, 11973, 7, false);" onblur="javascript: save_sentence(this, 11973, 7, true);">কোনো নৌকোয় মুর্শিদা বাউল গান হইতেছেঃ- এলাহির দরিয়ার মাঝে নিরাঞ্জনের খেলা, শিল পাথর ভাসিয়া গেল শুকনায় ডুবল ভেলা</textarea></td>
    <td><button class="jqbtn" onclick="javascript: return delocc(this, 2);">delete</button></td>
</tr>
</tbody>

Javascript:

var stable;
$crp(document).ready(function() {
    stable= $crp("#ssenttab").DataTable({
        "processing": true, "serverSide": true, "responsive": dresp, "jQueryUI": true, "searching":false, "order": [],
        "lengthMenu": [[5, 10, 15, 25, 50], [5, 10, 15, 25, 50]],
        "searchDelay": 1000,
        "columns": [
            {"data": "serial", "orderable": false},
            {"data": "title", "orderable": false},
            {"data": "authors", "orderable": false},
            {"data": "year"},
            {"data": "sentence", "orderable": false},
            {"data": "action", "orderable": false}
        ],
            "ajax": $crp.fn.dataTable.pipeline({
                "url": LexObj.auri+'panel/ajax/SpeechSentenceJSON',
                "type": "POST",
                "data": function(d){d.totalrec= snum; d.pskey=pskey;},
        }),
        "drawCallback": function(settings){
        $crp(".jqbtn").button();
        }
    });
});

function delocc(delobj, spskey)
{
    if(spskey>0)
    {
        if(confirm("Are you sure?"))
        {
            $crp.ajax({
                'url': LexObj.auri+'/panel/ajax/SpeechSentDelete',
                'data': {'dspsid': spskey},
                'type': 'POST',
                'dataType': 'jsonp',
                'success': function(result){
                    if(result.status>0)
                    {
                        var partr= $crp(delobj).parents('tr');
                        alert(partr.attr('class'); // works and ouputs either 'odd' or 'even'
                        stable.row(partr).remove().draw(false); // does not work
                        alert('ok'); //works
                    }
                }
            });
        }
    }
    return false;
}

有人可以举起一些光吗?提前表示感谢!

1 个答案:

答案 0 :(得分:0)

由于我使用的是pipelining,因此我需要在.draw()事件之前清除管道。

该行:

stable.rows(partr).remove().draw(false);

应该是

stable.rows(partr).remove().clearPipeline().draw(false);

这解决了问题。