【发布时间】:2017-11-14 11:06:13
【问题描述】:
我正在使用数据表来搜索表,但是当添加另一个表行时,我没有意识到在研究中我必须使用相同数量的行和列。我想知道有什么办法可以解决;因为我很想使用它,但我需要包含该表行。这就是我所拥有的。
Javascript
<script type="text/javascript">
$(document).ready(function () {
$('#data').DataTable();
});
</script>
表格
<h2>Transaction List</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div>
<h4>Transaction List Details</h4>
<div style="text-align:right">
@Html.ActionLink("Posted Items Report", "TransactionListRpt", "Post")
<input id="Print" type="button" value="Print Approved List" name="Print" class="btn-link"/>
</div>
<hr />
<table id="data" >
<thead>
@Html.CheckBox("TheOneCheckBoxToRuleThemAll")Select All
<tr>
<th class="col-lg-3 ">Expense Account</th>
<th class="col-lg-3 ">Item Number</th>
<th class="col-sm-1">Quantity</th>
<th class="col-sm-1 ">UOM</th>
<th class="col-sm-1 ">Cost</th>
<th class="col-sm-1 ">Extended Cost</th>
<th></th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
@Html.HiddenFor(m => m[i].requisitionNumber)
@Html.HiddenFor(m => m[i].inventory_acccount)
@Html.HiddenFor(m => m[i].department)
@Html.HiddenFor(m => m[i].docNumber)
@Html.HiddenFor(m => m[i].docType)
<tr>
<td>@Html.CheckBoxFor(m => m[i].postTrnx, new { @class = "checkGroup1" })</td>
<td class="label">
@Html.DisplayFor(m => m[i].requisitionNumber)
@Html.DisplayFor(m => m[i].transactionDate)
@Html.DisplayFor(m => m[i].docType)
</td>
</tr>
foreach (var item in Model[i].items)
{
@Html.HiddenFor(m => item.description)
@Html.HiddenFor(m => item.expense_account)
@Html.HiddenFor(m => item.itemNumber)
<tr>
<td class="col-lg-3 tabledata">@item.expense_account.account_desc</td>
<td class="col-lg-3 tabledata">@item.itemNumber</td>
<td class="col-sm-1 tabledata">@item.quantity</td>
<td class="col-sm-1 tabledata">@item.selecteduomtext </td>
<td class="col-sm-1 tabledata">@item.price</td>
<td class="col-sm-1 tabledata">@item.extended_cost</td>
<td>@Html.ActionLink("Edit", "Edit", new { id = @item.lineNum, name = Model[i].docNumber })</td>
</tr>
}
}
</tbody>
</table>
<br /><br /><br />
</div>
<div>
<input type="submit" value="Post" name="Approve" class="btn btn-primary btn-lg" onclick="return confirm('Click OK to continue or Cancel to abort');" />
@*<input type="button" value="View Posted Transactions" class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("TransactionListRpt","Post")'"/>*@
</div>
}
【问题讨论】:
-
DataTables 对 HTML 非常严格。首先,确保
@Html.CheckBox("TheOneCheckBoxToRuleThemAll")Select All在<th>中。 -
但这是个问题;我试图将它们添加到表中,然后我收到基于存储过程的错误@Html.CheckBoxFor(m => m[i].postTrnx, new { @class= "checkGroup1" }) @Html.DisplayFor(m => m[i].requisitionNumber) @Html.DisplayFor(m => m[i].transactionDate) @Html.DisplayFor(m => m[i].docType) -
我指的是表头的问题。您需要将第一个复选框放入广告中:
<thead><tr><th>@Html.CheckBox("TheOneCheckBoxToRuleThemAll")Select All</th> ...。这可能不是这里的问题,但我之前遇到过 DataTables 和错误 HTML 的问题。
标签: javascript jquery asp.net asp.net-mvc datatables