最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Delete a row of Bootstrap Table - Stack Overflow

programmeradmin7浏览0评论

Excuse me, now I am using this Bootstrap table. I don't know how to remove a row in the table, I have seen one similar example in the documentation, but I don't really understand what it means. Especially I don't know what {field: 'id', values: ids} means. The user experience I want to achieve is click button in any row that I want to remove, then that row will be removed.

Excuse me, now I am using this Bootstrap table. I don't know how to remove a row in the table, I have seen one similar example in the documentation, but I don't really understand what it means. Especially I don't know what {field: 'id', values: ids} means. The user experience I want to achieve is click button in any row that I want to remove, then that row will be removed.

Share Improve this question edited Nov 2, 2016 at 10:13 Mistalis 18.3k14 gold badges77 silver badges97 bronze badges asked Nov 2, 2016 at 9:46 Chih-Yu YehChih-Yu Yeh 651 gold badge2 silver badges9 bronze badges 1
  • Here is a examples of Bootstrap table usage: bootstrap-table.wenzhixin.cn/getting-started/#usage – Banzay Commented Nov 2, 2016 at 9:56
Add a ment  | 

2 Answers 2

Reset to default 5

Get defined bootstrap table as variable.

let table = $('#table');

Detect click event with remove button

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

In bootstrap-table elements in rows have data-index.

Next row getting clicked row index

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

Built in function for removing rows

    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]
    });
});
 $(document).on('click', 'button.removebutton', function () { // <-- changes
     $(this).closest('tr').remove();
     return false;
 });
发布评论

评论列表(0)

  1. 暂无评论