I am trying to add 2 extra columns for crud actions ie select and delete displaying an image in the column with a link via primary key. I cannot get it to show up or it says i have the incorrect number of columns. Table View
<table class="SearchResultsTable">
<thead>
<tr>
<th>
@Html.DisplayName("User Id")
</th>
<th>
@Html.DisplayName("User Email")
</th>
<th>
@Html.DisplayName("User Role")
</th>
<th>
@Html.DisplayName("Select")
</th>
<th>
@Html.DisplayName("Delete")
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.user_pk)
</td>
<td>
@Html.DisplayFor(modelItem => item.user_email)
</td>
<td>
@Html.DisplayFor(modelItem => item.user_type)
</td>
<td>
<a href="@Url.Action("GetUser", "User", new { id = item.user_pk })">
<img src="/Content/Images/SelectIcon.gif" alt="My Image" />
</a>
</td>
<td>
<a href="@Url.Action("GetUser", "User", new { id = item.user_pk })">
<img src="/Content/Images/DeleteIcon.gif" alt="My Image" />
</a>
</td>
</tr>
}
</tbody>
jquery
<script type="text/javascript">
$(document).ready(function () {
$(".SearchResultsTable").dataTable({
'bServerSide': true,
'bProcessing': true,
'sAjaxSource': '/User/FilteredUsers',
"bJQueryUI": true,
"bAutoWidth": false,
"bPaginate": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aoColumns": [
{ "sName": "user_pk",
"bSearchable": false,
"bSortable": false,
},
{ "sName": "user_email" },
{ "sName": "user_role" },
//{
// "mData": null, "bSearchable": false,
// "bSortable": false, "sClass": "editControl",
// "sDefaultContent": '<img src="/Content/Images/SelectIcon.gif" />'
//},
//{
// "mData": null, "bSearchable": false,
// "bSortable": false, "sClass": "editControl",
// "sDefaultContent": '<img src="/Content/Images/DeleteIcon.gif" />'
//}
]
/* make the first and last columns not sortable */
});
});
</script>
}
controller
// GET: /User/Details/5
public ActionResult FilteredUsers(jQueryDataTableParamModel param)
{
RestClient RestClientObject = new RestClient("http://domain");
var request = new RestRequest("api/user/", Method.GET);
request.AddParameter("page", param.iDisplayStart);
request.AddParameter("pageSize", param.iDisplayLength);
if (param.sSearch != null)
request.AddParameter("userName", param.sSearch);
IRestResponse<Pager<UserSummaryModel>> response = RestClientObject.Execute<Pager<UserSummaryModel>>(request);
IEnumerable<string[]> result = null;
try
{
result = from c in response.Data.pagedSet select new[] { Convert.ToString(c.user_pk), c.user_email, c.user_type };
}
catch
{
result = Enumerable.Empty<string[]>();
}
return Json(new
{
sEco = param.sEcho,
iTotalRecords = response.StatusCode == HttpStatusCode.OK ? response.Data.totalRecordSize : 0,
iTotalDisplayRecords = response.StatusCode == HttpStatusCode.OK ? response.Data.totalRecordSize : 0,
aaData = result
},
JsonRequestBehavior.AllowGet);
}
If I do not put the extra rows in result array in controller it says i have the incorrect columns numbers.. if i leave them out of the jquery i dont get the error but the columns are not populated. Please tell me how to do this