0

我需要隱藏我的表中的一些鏈接取決於另一列的值。隱藏鏈接在jquery datatable

<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>&nbsp&nbsp<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>&nbsp&nbsp<a href='/Groups/Delete/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Delete'><i class='fa fa-trash-o'></i></a>"; 
        } 
       } 
      ] 
     }); 
    } 
    } 
}(); 

如果第二列的值是「用戶」,我想隱藏編輯和刪除鏈接。

我正在考慮將隱藏邏輯添加到mRender,但我無法弄清楚如何獲得第二個值,因爲我已經傳遞了第一列的值。

感謝您的幫助。

回答

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>&nbsp&nbsp<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>&nbsp&nbsp<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; 
       } 
+0

這一工作的感謝。 – capiono