DataTables内联编辑,数据值为true时如何显示checkbox to checked
DataTables inline editing, how to display the checkbox to checked when the data value is true
我在 ASP MVC Net Core 3.1 项目中使用 DataTables 1.10.22,
我有一个内联复选框,当数据值为真时如何显示要选中的复选框?
所以,回到我下面的代码,filtered_ds.is_supervisor 是真还是假,我希望在 filtered_ds.is_supervisor 是真时选中自动复选框,如何完成这个?
{
orderable: false,
data: filtered_ds.is_supervisor,
render: function (data, type, row, meta) {
var idx = meta.row;
if (type === 'display')
{
return `<input type="checkbox" class="editor-is_supervisor" onclick="myfunc(this)"
id="${idx} " + (data == true ? 'checked':'') />`;
}
return data;
},
className: 'text-center align-middle'
您可以尝试使用:
if (type === 'display')
{
if (filtered_ds.is_supervisor)
{
return "<input type='checkbox' class='editor-is_supervisor' onclick='myfunc(this)' id='" + idx + "' checked />";
} else
{
return "<input type='checkbox' class='editor-is_supervisor' onclick='myfunc(this)' id='" + idx + "' />";
}
}
我在 ASP MVC Net Core 3.1 项目中使用 DataTables 1.10.22, 我有一个内联复选框,当数据值为真时如何显示要选中的复选框? 所以,回到我下面的代码,filtered_ds.is_supervisor 是真还是假,我希望在 filtered_ds.is_supervisor 是真时选中自动复选框,如何完成这个?
{
orderable: false,
data: filtered_ds.is_supervisor,
render: function (data, type, row, meta) {
var idx = meta.row;
if (type === 'display')
{
return `<input type="checkbox" class="editor-is_supervisor" onclick="myfunc(this)"
id="${idx} " + (data == true ? 'checked':'') />`;
}
return data;
},
className: 'text-center align-middle'
您可以尝试使用:
if (type === 'display')
{
if (filtered_ds.is_supervisor)
{
return "<input type='checkbox' class='editor-is_supervisor' onclick='myfunc(this)' id='" + idx + "' checked />";
} else
{
return "<input type='checkbox' class='editor-is_supervisor' onclick='myfunc(this)' id='" + idx + "' />";
}
}