bootstrap table updateCellByUniqueId根据唯一字段更新单元格数据的方法

bootstrap table updateCellByUniqueId更新单元格数据,参数列表如下。

updateCellByUniqueId方法

参数名称参数说明
id唯一字段(或主键)对应的值
field需要更新的字段
value该字段需要被更新的值

代码例子

 //设置唯一字段
 $('#table').bootstrapTable({  
    toolbar:"#toolbar",  
    uniqueId:"code",//设置唯一字段
    data:data,
    columns: columns,  
  });
 //更新Id为11的行 的catalog字段为newValue
 $('#table').bootstrapTable('updateCellByUniqueId', {
     id: 'x6',
      field: 'catalog',
     value: 'newValue'
  })

在线试一试 

完整例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://www.itxst.com/package/jquery-3.3.1/jquery.js"></script>
    <link href="https://www.itxst.com/package/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
    <link href="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.css" rel="stylesheet" />
    <script src="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.js"></script> 
    <title>bootstrap table updateCellByUniqueId在线例子</title>
    <style>
        .table-demo {
            width: 80%;
            margin: 30px auto 0px auto;
        }
      .titles {
  float: right;
  clear: both;
}
    </style>
</head>
<body>
  <div id="toolbar">
    <button onclick="update()">更新第Id为11的单元格数据</button> 
  </div>
    <div class="table-demo">
        <table id="table"  ></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [
        { 
          checkbox:true
        },
        { 
           field:"code",  
          title: 'code'
        }, {
            field: 'catalog',
            title: '分类'
        } ];
      var data= [{
            code: 'x6',
            catalog: 'catalog 001', 
        }, {
            code: 'x7',
            catalog: 'catalog 002', 
        }, {
            code: 'x8',
            catalog: 'catalog 003', 
      } ];
        
      //设置唯一字段
     $('#table').bootstrapTable({  
        toolbar:"#toolbar", 
        uniqueId:"code",
        data:data,
        columns: columns,  
      });
      
     function update()
     {
       
      $('#table').bootstrapTable('updateCellByUniqueId', {
        id: 'x6',
        field: 'catalog',
        value: 'newValue'
      });
    }
    </script>
</body>
</html>