I am a beginner using jQuery DataTable, and I am trying to place Edit and Delete buttons in a jQuery DataTable with dynamic databinding in bootstrap like in the below image:
But I get an error message:
Controller Action
public class PhoneNumber
{
public string Number { get; set; }
public string Description { get; set; }
public string Action { get; set; }
}
public ActionResult LoadPhoneNumbers()
{
var phoneNumbers = new List<PhoneNumber>(new[]
{
new PhoneNumber { Number = "555 123 4567", Description = "George",Action="" },
new PhoneNumber { Number = "555 765 4321", Description = "Kevin" ,Action="" },
new PhoneNumber { Number = "555 555 4781", Description = "Sam",Action="" }
});
return Json(new
{
aaData = phoneNumbers.Select(x => new[] { x.Number, x.Description })
}, JsonRequestBehavior.AllowGet);
}
HTML
<table id="tblAdminUsers" class="table table-striped table-bordered table-hover table-highlight table-checkable"
data-info="true"
data-search="true"
data-paginate="true">
<thead>
<tr>
<th>Number</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Script
$(function () {
$("#tblAdminUsers").dataTable({
bProcessing: true,
sAjaxSource: '@Url.Action("LoadPhoneNumbers", "Admin")',
aoColumns: [
{ mData: "Number" },
{ mData: "Description" },
{
mData: "Action",
bSortable: false,
mRender: function (o) { return '<i class="ui-tooltip fa fa-pencil" style="font-size: 22px;" data-original-title="Edit"></i><i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete"></i>'; }
}
]
});
});
I just remove the mData
attribute in aoColumns
property
in dataTable Script.
$(function () {
$("#tblAdminUsers").dataTable({
bProcessing: true,
sAjaxSource: '@Url.Action("LoadPhoneNumbers", "Admin")',
aoColumns: [
{ bSortable: false, },
{ bSortable: false, },
{
bSortable: false,
mRender: function (o) { return '<i class="ui-tooltip fa fa-pencil" style="font-size: 22px;" data-original-title="Edit"></i><i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete"></i>'; }
}
]
});});
just follow this url:http://editor.datatables.net/examples/styling/envelopeInTable.html. This will solve your concern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With