I have this datatable (version 1.10.4) In one of the columns in my datatable I display buttons. Based on a boolean in my model, I want to hide or show those buttons. I can't seem to get it working. Can ayone help me?
This is my model:
Public Class ArtistDetailDto
Public Property Id As Integer
<Required(ErrorMessage:="Name is required.")> _
Public Property Name As String
Public Property NumberOfAlbums As Integer
Public Property Albums As List(Of AlbumDetailDto)
Public Property CanBeDeletedOrUpdated As Boolean
End Class
This is the HTML for my table:
<table width="100%" class="table table-striped table-bordered" id="artists" cellspacing="0">
<thead>
<tr> <th>Name</th> <th>Number Of Albums</th><th>Action</th></tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem >= item.Name)</td>
<td>@Html.DisplayFor(modelItem >= item.NumberOfAlbums)</td>
<td>
<input type="button" id="albumButton" value="Albums" onclick=" location.href='@Url.Action("Index", "Albums", new {id = item.Id})' " class=" btn btn-default" />
<input type="button" id="editButton" value="Edit" onclick=" location.href='@Url.Action("Edit", "Artists", new { id = item.Id })' " class=" btn btn-default" />
<input type="button" id="deleteButton" value="Delete" onclick=" location.href='@Url.Action("Delete", "Artists", new { id = item.Id })' " class=" btn btn-default" />
</td>
</tr>
}
</tbody>
</table>
And this is the script for my datatable :
$(function () {
//var buttonPlaceholder = $("#buttonPlaceholder").html("<button>Add</button>");
oTable = $("#artists").dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"sDom": '<"top"if>rt<"bottom"<"#buttonPlaceholder">lp><"clear">',
"aoColumns":
[
/* ArtistName */ { "bSortable": true, "bSearchable": true, "width": "50%" },
/* NumberOfAlbums */ { "bSortable": true, "bSearchable": true, "width": "10%" },
/* Action */ { "bSortable": false, "bSearchable": false, "width": "10%" }
]
});
});
So based on the value of the boolean CanBeUpdatedOrDeleted, I want to hide or show the "edit"- and "delete"-button.