Getting values of selected table rows in bootstrap using jquery

前端 未结 4 638
一生所求
一生所求 2020-12-08 05:46

I\'m using bootstrap table. In that I want to get Item ID value/values of selected table rows after clicking \'Add to cart\' button present on same

4条回答
  •  旧时难觅i
    2020-12-08 06:21

    Just use the check.bs.table and uncheck.bs.table events to collect your checked rows.

    BS-Table Basic Events

    Here is an example:

    var checkedRows = [];
    
    $('#eventsTable').on('check.bs.table', function (e, row) {
      checkedRows.push({id: row.id, name: row.name, forks: row.forks});
      console.log(checkedRows);
    });
    
    $('#eventsTable').on('uncheck.bs.table', function (e, row) {
      $.each(checkedRows, function(index, value) {
        if (value.id === row.id) {
          checkedRows.splice(index,1);
        }
      });
      console.log(checkedRows);
    });
    
    $("#add_cart").click(function() {
      $("#output").empty();
      $.each(checkedRows, function(index, value) {
        $('#output').append($('
  • ').text(value.id + " | " + value.name + " | " + value.forks)); }); });
    
    
    
    
    
    
    
    Name Stars Forks Description

    提交回复
    热议问题