Getting values of selected table rows in bootstrap using jquery

前端 未结 4 634
一生所求
一生所求 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条回答
  •  既然无缘
    2020-12-08 06:03

    To get the selected (checked) rows, use getSelections method.

    Note that if you are using pagination, then you have to use the maintainMetaData table option.

    Here is an example which displays selected product's names when user clicks on Ad to cart button:

    var $table = $('#myTable');
    
    function getRowSelections() {
      return $.map($table.bootstrapTable('getSelections'), function(row) {
        return row;
      })
    }
    
    $('#showSelectedRows').click(function() {
      var selectedRows = getRowSelections();
      var selectedItems = '\n';
      $.each(selectedRows, function(index, value) {
        selectedItems += value.name + '\n';
      });
    
      alert('The following products are selected: ' + selectedItems);
    });
    
    
    
    
    
    
    
    
    Item ID Product Name Price
    1 Chair $80
    2 Sofa $500
    3 Desk $300
    4 Rug $200

提交回复
热议问题