bootstrap table getRowByUniqueId根据唯一Id获取行数据的方法

bootstrap table getRowByUniqueId根据唯一Id获取行数据,使用此方法的前提是要指定那列字段为唯一字段(主键字段)。

getRowByUniqueId方法

参数名称参数说明
id唯一字段列对应的值,(主键字段对应的值)

代码例子

//设置code为唯一字段(主键字段)
 $('#table').bootstrapTable({  
         toolbar:"#toolbar",  
         uniqueId:"code",
         data:data,
         columns: columns,  
 });
 //获取code字段值为C6的行数据 
 function getByUID()
{
       var rs=$('#table').bootstrapTable('getRowByUniqueId','C6');
       alert(JSON.stringify(rs));
}

在线试一试 

完整例子

<!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 getRowByUniqueId在线例子</title>
    <style>
        .table-demo {
            width: 80%;
            margin: 30px auto 0px auto;
        }
      .titles {
  float: right;
  clear: both;
}
    </style>
</head>
<body>
  <div id="toolbar">
    <button onclick="getByUID()">根据唯一字段获取行数据</button> 
  </div>
    <div class="table-demo">
        <table id="table"  ></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [  { 
           field:"id",  
           title: 'ID'
        }, {
            field: 'code',
            title: '编码(为列主键字段)'
        } ];
      var data= [{
            id: 10,
            code: 'C5', 
        }, {
            id: 10,
            code: 'C6', 
        }, {
            id: 30,
            code: 'C7', 
         } ];
        
    //设置code为唯一字段(主键字段)
     $('#table').bootstrapTable({  
         toolbar:"#toolbar",  
         uniqueId:"code",
         data:data,
         columns: columns,  
      });
     //获取code字段值为C6的行数据 
     function getByUID()
     {
       var rs=$('#table').bootstrapTable('getRowByUniqueId','C6');
       alert(JSON.stringify(rs));
      }
  
    </script>
</body>
</html>