您的位置:首页 > Web前端 > BootStrap

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

2020-05-28 14:02 183 查看

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

//配置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)),
}
});

转载于:https://www.dsboke.com/2020/05/28/bootstrap_table_gen_ju_id_wei_yi_biao_shi_cha_xun_biao_ge_bing_xiu_gai_geng_xin_cha_xun_dao_de_xing/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐