how to Disable / Enable button with href in datatable

how to Disable / Enable button with href in datatable

huynbt09huynbt09 Posts: 1Questions: 1Answers: 0
edited March 2021 in Free community support

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']
    });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Is this using Editor?

    If not, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.