layui table默认选中指定行

时间:2022-05-31 07:55:14

表格默认选中行,在回调里写入

done: function (res, curr, count) {
tableData = res.data;
$("[data-field='id']").css('display', 'none');
var data = res.data;
var num = 0;
for (var i = 0; i < data.length; i++) {
if (ExamStudentArray.indexOf(data[i].id) != -1) {
num++;
var index = data[i]['LAY_TABLE_INDEX'];
$('#examPlanForm tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
$('#examPlanForm tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
}
}
var limit = $(".layui-laypage-limits").find("option:selected").val(); //分页数目
if ((num == limit || num == count) && count > 0) {
$('#examPlanForm .layui-table-header table.layui-table thead th input[type="checkbox"]').prop('checked', true);
$('#examPlanForm .layui-table-header table.layui-table thead th input[type="checkbox"]').next().addClass('layui-form-checked');
}
form.render();
}