[英]Disabled button not working in Datatables?
I am checking the status
of the Model I am using, but the Edit button still works normally without being disabled as expected.我正在检查我正在使用的 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']
});
Actually you are using anchor tag, and disable property working with input type elements, so you need to change <a />
with <button />
实际上您正在使用锚标记,并禁用与输入类型元素一起使用的属性,因此您需要将<a />
更改为<button />
here is example这是示例
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.