我需要隐藏我桌子上的一些链接,具体取决于另一列的值。
<tbody>
@foreach (var group in Model) {
<tr>
<td>
@Html.Raw(group.Id)
</td>
<td>
@Html.Raw(group.Name)
</td>
<td>
@Html.Raw(group.Description)
</td>
<td></td>
</tr>
}
</tbody>
var InitiatizeGroup = function () {
return {
init: function () {
var oTable = $('#groups').dataTable({
"dom": "flt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
"aaSorting": [[1, 'asc']],
"language": {
"search": "",
"sLengthMenu": "_MENU_",
"oPaginate": {
"sPrevious": "Prev",
"sNext": "Next"
}
},
"aoColumns": [
{
"bVisible": false,
"bSearchable": false,
"bSortable": false,
},
null,
null,
{
mData: 0,
"bSearchable": false,
"bSortable": false,
sClass: "alignCenter",
"mRender": function (data, type, full) {
return "<a href='/Groups/Details/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Details'><i class='fa fa-info-circle'></i></a>  <a href='/Groups/Edit/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Edit'><i class='fa fa-pencil-square-o'></i></a>  <a href='/Groups/Delete/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Delete'><i class='fa fa-trash-o'></i></a>";
}
}
]
});
}
}
}();
如果第二列的值是&#34;用户&#34;我想隐藏编辑和删除链接。
我正在考虑将隐藏逻辑添加到mRender,但我无法弄清楚如何获得第二个值,因为我已经传递了第一列的值。
感谢您的帮助。
答案 0 :(得分:1)
mRender
中的第三个参数是包含所有列数据的数组。要访问第二列的值,请使用full[1]
。
示例:
"mRender": function (data, type, full) {
if(full[1] === "Users"){
data = "<a href='/Groups/Details/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Details'><i class='fa fa-info-circle'></i></a>  <a href='/Groups/Edit/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Edit'><i class='fa fa-pencil-square-o'></i></a>  <a href='/Groups/Delete/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Delete'><i class='fa fa-trash-o'></i></a>";
} else {
data = "";
}
return data;
}