#javascript #ajax #button #datatables
Вопрос:
Я проверяю 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']
});
Ответ №1:
На самом деле вы используете тег привязки и отключаете свойство, работающее с элементами типа ввода, поэтому вам нужно изменить <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 ....
}