bootstrap table 根据id唯一标识查询表格并修改更新查询到的行

首先介绍如何根据唯一标识查询对应的行数据:

//配置table
$("#table-list-webhoo").bootstrapTable({
    ..............//省略一部分配置参数
    uniqueId : 'goodsId',  //这个参数必须得配置,设置唯一标识的对应字段,对应下面columns配置的字段名称
    columns : [{
        title : 'Id',
        field : 'goodsId',
        visible:false,//隐藏此列,这里隐藏了id这个字段
    },{
        title : '序号',
        field : 'xh',
        formatter: function (value, row, index) {
            return index+1;
        }
    },{
        title : '商品名称',
        field : 'goods_name',
    }, {
        title : '编码',
        field : 'code',
    }, {
        title : '规格',
        field : 'goods_spec',
    },{
        title : '单位',
        field : 'unit',
    },{
        title : '单价',
        field : 'sale_price',
    },{
        title : '售价',
        field : 'sale_money',
    },{
        title : '数量',
        field : 'goods_count',
    },{
        title : '小计',
        field : 'goods_money',
        sortable : true
    },{
        title : '操作',
        field : 'opt',
        formatter: function () {
            return '\
                <div class="btn-group btn-group-sm">\
                  <button type="button" class="btn btn-danger">删除</button>\
                </div>';
        }
    }]
  });

使用getRowByUniqueId 获取对应行数据:

var checkData=$("#table-list-webhoo").bootstrapTable('getRowByUniqueId',goodsId);
//goodsId就是您上面设置的唯一标识字段值

修改查询到的行某些字段值:

//修改当前行数据,goodsId就是您上面设置的唯一标识字段值
$("#table-list-webhoo").bootstrapTable('updateByUniqueId',{
   id:goodsId,
   row: {
     goods_count: odCount+1,  //这些字段值请根据您自己的需求去修改
     goods_money:toMoney(Number(checkData.sale_money)*(odCount+1)),
   }
 });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值