我正在使用Bootstrap-Table Cn
我有一张桌子。我想预先检查某些行。但是,当我在表行中添加class="selected"
时,在加载表时,Bootstrap-Table会删除所选的类并取消选中它。在表格加载之前,如何保存选中的初始复选框?
更新:我没有创建复选框输入。我正在使用BootStrap Tables CN为我生成复选框。
这是代码。
<table id="storeTable" class="table table-bordered table-hover" style="width:100%" data-toggle="table" data-search="true" data-toolbar="#toolbar" data-pagination="true" data-side-pagination="client" data-show-pagination-switch="true" data-page-list="[10, 25, 50, ALL]" data-click-to-select="true" data-filter>
<thead>
<tr>
<th data-sortable="true" data-checkbox="true">
</th>
<th data-field="cg" data-sortable="true">
@Html.DisplayNameFor(model => model.dealeradminstore[0].cg)
</th>
<th data-field="sn" data-sortable="true">
@Html.DisplayNameFor(model => model.dealeradminstore[0].serial_number)
</th>
<th data-field="name" data-sortable="true">
@Html.DisplayNameFor(model => model.dealeradminstore[0].Name)
</th>
<th data-sortable="true">
WebReports
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.dealeradminstore)
{
<tr id="@test.NullRefExcl(item.serial_number.ToString())" checked>
<td></td>
<td>
@test.NullRefExcl(item.cg.ToString())
</td>
<td>
@test.NullRefExcl(item.serial_number.ToString())
</td>
<td>
@test.NullRefExcl(item.Name)
</td>
<td>
@{string reportsCheck = "";
if (test.NullRefExcl(item.base_xtags).Contains("RPT"))
{
reportsCheck = "Yes";
}
if (!test.NullRefExcl(item.base_xtags).Contains("RPT"))
{
reportsCheck = "No";
}
}
@test.NullRefExcl(reportsCheck)
</td>
</tr>
}
</tbody>
</table>
答案 0 :(得分:0)
要创建一个动态生成的复选框并将其值设置为选中状态:
@Html.CheckBoxFor(m => m.SomeBooleanProperty, new { @checked = "checked" });
答案 1 :(得分:0)
最后,从Richard0096向正确的方向指出一点,我就能弄清楚了。这是使用Bootstrap Tables Extensions CN的解决方案。
var checkSum = 0;
function checkedFormatter(value, row, index) {
var snList = [];
snList = document.getElementById("inputsn").value.split("|");
snList.forEach(function (element) {
var checkSN = ((row.sn).toString()).trim();
if (checkSN == element) {
checkSum = 1;
}
})
if (checkSum == 1) {
checkSum = 0;
return {
checked: true
}
}
return value;
}