删除一行Bootstrap表

时间:2016-11-02 09:46:22

标签: javascript html css twitter-bootstrap

对不起,现在我正在使用这个Bootstrap table。我不知道如何删除表格中的一行,我在文档中看到了one similar example,但我并不真正理解它的含义。特别是我不知道{field: 'id', values: ids}的含义。我想要实现的用户体验是我要删除的任何行中的单击按钮,然后该行将被删除。

2 个答案:

答案 0 :(得分:1)

将定义的引导程序表获取为变量。

let table = $('#table');

使用删除按钮检测点击事件

$(document).on('click', '.removeRowButton', function() {

在引导表中,行中的元素具有数据索引。

下一行获得点击的行索引

    let rowid = $(this).closest('tr').data('index');

内置删除行的功能

    table.bootstrapTable('remove', {
      field: '$index',
      values: [rowid]
    });


let table = $('#table');
$(document).on('click', '.removeRowButton', function() {
    let rowid = $(this).closest('tr').data('index');
    table.bootstrapTable('remove', {
      field: '$index',
      values: [rowid]
    });
});

答案 1 :(得分:-1)

 $(document).on('click', 'button.removebutton', function () { // <-- changes
     $(this).closest('tr').remove();
     return false;
 });