var checkedIds = "1,2,3";// 要选中的ID, 也可以在后台封装 dataIsChecked
table = $.extend(table, {config: {checkName: 'dataIsChecked'}});
table.render({
elem: '#dataTable',
id: 'dataTable',
url: tableUrl,
width: admin.screen() > 1 ? '100%' : '',
height: $win.height() - 90,
limit: 20,
limits: [20, 40, 60, 80, 100, 200],
toolbar: '#headerToolBar',
defaultToolbar: [],
request: {
pageName: 'page',
limitName: 'rows'
},
cols: [
[
{type:'checkbox', fixed: 'left'},
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
]
],
page: true,
parseData: function(data) {
var list = data.rows;
if(checkedIds && checkedIds != 'undefined') {
for(var i = 0 ; i < list.length ; i++) {
var id= list[i].id;
if(checkedIds.indexOf(id) != -1) {
data.rows[i].dataIsChecked= true; // 让其选中
}else {
data.rows[i].dataIsChecked= false; // 不选中
}
}
}
return {
'code': 0,
'msg': '',
'count': data.total,
'data': data.rows
};
}
});
Layui列表渲染的时候让数据选中状态回显
|