【发布时间】:2017-07-23 14:49:27
【问题描述】:
我有一个 $datatables 和 $datatables row.add() API 一起工作,所以我可以实现我想要的。现在,我有一个对象e.data,它将使用row.add() 作为新行添加。一切正常,直到有一天我需要添加td class="hidden" td。它添加成功,但邪恶的情况来了。 td class="hidden"td 没有发生,tdtd 发生了。我的数百万美元的问题是如何在使用数据表添加 td 类时保留它。
Buttons html 属性添加成功。 tds 属性?我不知道为什么它没有显示。
非常感谢!
下面是代码
if (e.success == "TrueAdd") {
var table = $('#product-table').DataTable();
var arr = $.map(e.data, function (value, index) { return [value]; });
var newValue = [arr[0], '<td style="visibility:hidden">' + arr[1] + '</td>', arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8],
'<button type="button" class="btn-edit btn btn-info btn-default">Edit</button>',
'<button type="button" class="btn-delete btn btn-info btn-default">Delete</button>'];
table.row.add(newValue).draw(false);
}
<table id="product-table" class="table">
<thead>
<tr>
<th>Product Id</th>
<th class="hidden">CategoryId</th>
<th>Category</th>
<th>Manufacturer</th>
<th>Name</th>
<th>Description</th>
<th>Model</th>
<th>Released Date</th>
<th>Released Year</th>
<th>Action</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ProductList)
{
<tr>
<td>@item.Id</td>
<td>@item.CategoryId</td>
<td>@item.CategoryDescription</td>
<td>@item.ManufacturerId</td>
<td>@item.Name</td>
<td>@item.Description</td>
<td>@item.Model</td>
<td>@item.ReleasedDate</td>
<td>@item.ReleasedYear</td>
<td><button type="button" class="btn-edit btn btn-info btn-default">Edit</button></td>
<td><button type="button" class="btn-delete btn btn-info btn-default">Delete</button></td>
</tr>
}
</tbody>
</table>
【问题讨论】:
-
请告诉我您是否正在研究解决方案或其他问题
-
也许使用 DataTable 来创建你的按钮而不是硬编码它们,它们添加你的数组但没有标记?
-
按钮不是问题,
是问题所在,每次我附加一些东西时我都需要隐藏 td,但是当我附加一个隐藏的 span 类时会显示一个空格新的 td。
标签: javascript jquery html css datatables