简体   繁体   中英

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.

        $(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 />

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 ....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM