0

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

1 Answer 1

1

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 ....
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.