【发布时间】:2021-05-08 06:38:32
【问题描述】:
我正在从模型列表创建一个可编辑的 JQuery 数据表。我想编辑表中列出的每条记录的某些列 [Rate, Qty, IsBranded, Description]。我的代码如下。
ProductModel
Id int
Name string
Rate decimal
Qty int
Price decimal
Description string
HTML 和 JavaScript
<script type="text/javascript">
$("document").ready(function () {
$('#tbllist').DataTable();
});
</script>
@model List<Product>
<table id="tbllist" class="cell-border" style="width:100%">
<thead class="thead-light">
<tr>
<td>Name</td>
<td>Rate</td>
<td>Qty</td>
<td>total</td>
<td>IsBranded</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@if (Model != null)
{
for (var i = 0; i < Model.Count; i++)
{
<tr>
<td>@Model[i].Name</td>
<td>@Model[i].Rate</td>
<td>@Model[i].Qty</td>
<td>@Model[i].total</td>
<td><input type="checkbox" @(Model[i].IsBranded ? "checked" : "") /></td>
<td>@Model[i].Description</td>
</tr>
}
}
</tbody>
</table>
我想编辑 Rate、Qty、Description、IsBranded 列。如果有人可以帮助我制作适当的代码,将不胜感激。
感谢 艾伦
【问题讨论】:
-
你可以使用CellEdit插件。
-
也许这个例子会对你有所帮助:editor.datatables.net/examples/inline-editing/simple
-
我正在寻求有关如何在我现有代码中应用代码的人的帮助。谢谢
-
你最后是怎么解决你的问题的?
标签: html jquery asp.net-core datatable