Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello ,I want to check the Article's Status, if true the Edit button will be disabled else the user can click and switch to the Edit page. How to use it?


$(document).ready(function () {
    var table = $('#studentArticleTable').DataTable();
    var button = table.button
    ({
        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");
            }},
            {
                data: 'id',
                className: "center",
                title: 'Actions',
                render: function (data) {
                    @if (Model.Status == true)
                    {
                        
                    }
                    else
                    {
                        
                    }
                    return '<a href="Student/EditArticle/' + data + '" class="btn btn-success mr-1"> Edit </a>';
                }}
        ],
        order: [1, 'asc']
    });


What I have tried:

I tried creating the button from the Datatables example but it didn't help me get to the hrel I wanted
Posted
Updated 17-Mar-21 10:16am

1 solution

@Model.Status will affect every record. Is that what you want? Are you sure you don't want to check a value of the particular row?

It's really easy. In your render event get a value like this:
JavaScript
 var rowvalue = row["some_field_in_dataset"];
var html;
if (rowvalue ==""){
   html = "<button id=......"
}
else {
  html = ""// html for a disabled button
}
return html;
 
Share this answer
 
Comments
huynbt209 17-Mar-21 16:22pm    
use it in @Model.Status?
huynbt209 17-Mar-21 16:24pm    
I am not really good at working with javascript, can you help me more fully?
SeanChupas 17-Mar-21 16:25pm    
What more do you need?
huynbt209 17-Mar-21 16:28pm    
@if (Model.Status == true)
{

}
else
{

}
return ' Edit ';
}}
huynbt209 17-Mar-21 16:28pm    
Would you like me to do it here?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900