layui table中使用checkbox
Posted tangbang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了layui table中使用checkbox相关的知识,希望对你有一定的参考价值。
第一步:
1.
<div class="layui-form"> <table class="layui-hide" lay-filter="js_table_reource_invite_supplier_index_table" id="js_table_reource_invite_supplier_index_table"></table> </div>
2.渲染表格
table.render({ elem: ‘#js_table_reource_invite_supplier_index_table‘, data:[], cellMinWidth: 80, maxHeight:300, loading: true, even: true, method: ‘POST‘, cols: [ [ {type: ‘numbers‘, title: ‘序号‘}, {type: ‘checkbox‘, width: 50}, {field: ‘provider_name‘, title: ‘供方名称‘,width: 150}, {field: ‘is_qualified‘, title: ‘是否合格‘,width: 100, align: ‘center‘,templet:function(row){ var html = "<input type=‘checkbox‘ lay-skin=‘primary‘ lay-filter=‘checkboxIsSelected‘ table-index=‘"+row.LAY_TABLE_INDEX+"‘ class=‘checkboxIsSelected‘ value=‘1‘ "; if(row.is_qualified == 1){ html += " checked "; } html += ">"; return html; }}, { field:‘remark‘, title: ‘综合评语‘, align: ‘center‘,edit: ‘text‘ } ]], done: function (obj) { layer.closeAll(); form.on(‘checkbox(checkboxIsSelected)‘, function(data){ var _index = $(data.elem).attr(‘table-index‘)||0; if(data.elem.checked){ obj.data[_index].is_qualified = data.value; }else{ obj.data[_index].is_qualified = 2; } }); } });
第二步,获取表格中的数据
var supplierList = table.cache.js_table_reource_invite_supplier_index_table;
table.render({ elem: ‘#js_table_reource_invite_supplier_index_table‘, data:[], cellMinWidth: 80, maxHeight:300, loading: true, even: true, method: ‘POST‘, cols: [ [ {type: ‘numbers‘, title: ‘序号‘}, {type: ‘checkbox‘, width: 50}, {field: ‘provider_name‘, title: ‘供方名称‘,width: 150}, {field: ‘is_qualified‘, title: ‘是否合格‘,width: 100, align: ‘center‘,templet:function(row){ var html = "<input type=‘checkbox‘ lay-skin=‘primary‘ lay-filter=‘checkboxIsSelected‘ table-index=‘"+row.LAY_TABLE_INDEX+"‘ class=‘checkboxIsSelected‘ value=‘1‘ "; if(row.is_qualified == 1){ html += " checked "; } html += ">";return html; }}, { field:‘remark‘, title: ‘综合评语‘, align: ‘center‘,edit: ‘text‘ } ]], done: function (obj) { layer.closeAll();form.on(‘checkbox(checkboxIsSelected)‘, function(data){var _index = $(data.elem).attr(‘table-index‘)||0; if(data.elem.checked){ obj.data[_index].is_qualified = data.value;}else{ obj.data[_index].is_qualified = 2; }}); } });
以上是关于layui table中使用checkbox的主要内容,如果未能解决你的问题,请参考以下文章