I've got a $datatables
and $datatables row.add()
API working together so I can achieve what I want. Now, I've got an object e.data
that will be added as a new row using row.add()
. Everything is working fine until one day I needed to add td class="hidden" td
. It added successfully but an evil situation came. td class="hidden"td
did not happen, tdtd
happened. My multi million dollar question is how to retain the class of td
when adding it using datatable.
Buttons html attributes adds successfully. tds
attributes? I don't know why its not showing.
Thank you so much!
Below is the code
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>