[英]Disabled button not working in Datatables?
我正在檢查我正在使用的 Model 的status
,但編輯按鈕仍然可以正常工作,而不會像預期的那樣被禁用。
$(document).ready(function () {
$('#studentArticleTable').DataTable({
info: false,
ajax: {
url: '/Student/GetPersonalArticles',
dataSrc: ''
},
rowId: "id",
columns: [
{ data: 'title', title: 'Title' },
{ data: 'faculty.facultyName' , title: 'Faculty' },
{ data: 'status', title: 'Status', render: function (data)
{
if (data == false) {
return 'Waiting for Approve';
} else {
return 'Approved';
}
}
},
{data: 'createAt', title: 'Create At', render: function (data){
return moment(data).format("HH:mm - DD/MM/YYYY");
}},
{
data: 'updateAt', title: 'Update At', render: function (data) {
return moment(data).format("HH:mm - DD/MM/YYYY");
}
},
function myfuncion (url) { window.location.assign(url) },
{
data: 'id',
className: "center",
title: 'Actions',
render: function (data, type, row) {
if (row.status === true)
{
return '<button onclick="myfunction('Student/EditArticle/' + data)" class="btn btn-success mr-1"> Edit </button>';
}
else
{
return '<button onclick="myfunction('Student/EditArticle/' + data)" class="btn btn-success mr-1" disabled> Edit </button>';
}
}
}
],
order: [1, 'asc']
});
實際上您正在使用錨標記,並禁用與輸入類型元素一起使用的屬性,因此您需要將<a />
更改為<button />
這是示例
render: function (data, type, row) {
if (row.status === true)
{
return '<button onclick="myfunction('+"Student/EditArticle/" + data+')" class="btn btn-success mr-1"> Edit </button>';
}
else
{
return '<button onclick="myfunction('+"Student/EditArticle/" + data+')" class="btn btn-success mr-1" disabled> Edit </button>';
}
}
function myfunction (url) {
// rest logic here ....
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.