簡體   English   中英

如何在條件下禁用 jquery 數據表中的渲染功能?

[英]How to disable the render function in jquery datatable with condition?

我已經表明我的datatable下面的jQuery。

 $(document).ready(function () {
    DataTable(
    'StudentDetails',
    'student Details',
       [
       { "data": "StudentName", "name": "StudentName", "autoWidth": true },
       {
         "orderable": false,
         "searchable": false,
         "className": 'text-right',
         "render": function (data, type, full, meta) {
            return '<a class="btn" href="UserLevels/' + full.StudentName+ '">Details</button>' +
                   '<a class="btn" href = "UserLevels/' + full.StudentName+ '/Edit">Edit</a>'; 
                    }
              }
          ],
          [

          ],
           'StudentDetails/LoadData',
            );
        });

在這里,當studentName為“Admin”時,我想禁用<a>標簽內的buttons (詳細信息、編輯)。 有任何想法嗎 ???

如果StudentNameAdmin ,不要禁用按鈕,而不是禁用它。 您可以在綁定按鈕之前檢查StudentName ,如下所示:

"render": function(data, type, full, meta) {
  if (full.StudentName != 'Admin') {
    return '<a class="btn" href="UserLevels/' + full.StudentName + '"> Details </button>' +
           '<a class="btn" href = "UserLevels/' + full.StudentName + '/Edit"> Edit </a>';
  } else
    return '';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM