1

I need enable or disable the checkbox in my datatable base of the value of the 'Status' column. I want the checkbox to be disable when the status is "Closed". I know I can stop displaying the close ticket by changing the where clause in my query. but i want to user to be able to see all tickets

Table display

enter image description here

C# Code

 public ActionResult GetChildTickets1(int id)
    {
        _db.Configuration.ProxyCreationEnabled = false;
        IQueryable<VmRequest> results = _db.VmRequests.Where(i => i.ParentId == id) ;
        return Json(results, JsonRequestBehavior.AllowGet);
    }

JQuery Code

 // Datatable value from the database
  var enabletemplateListVM;
    function tchildticket () {
        enabletemplateListVM = {
            dt: null,
            init: function () {
                dt = $('#childtable').DataTable({
                    "pageLength": 10,                                              
                    "ajax": {
                        // Url
                        "url": "/Home/GetChildTickets1?id="[email protected],
                        "type": "POST",
                        "datatype": "json",
                        "dataSrc": function (d) {
                            return d
                        }
                    },
                     // Table Columns to display the data
                    "columns": [                            
                   {
                            "targets": [0],
                            "data": "Id", "autoWidth": true,
                            "render": function (data, type, full) {
                                return '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '"/>';
                            },
                        },
                        { "title": "Ticket Id", "data": "Id", "name": "Id" },
                        {
                            "title": "Logged On", "data": "CreatedOn", "name": "CreatedOn",
                            // Date Formating
                          render: function (data, type, full, meta) {
                                if (data !== null) {
                                    return (moment(data).format("DD/MM/YYYY"));
                                } else {
                                    return '';
                                }
                            }
                        },
                        { "title": "Ticket Type", "data": "TypeofWork", "name": "TypeofWork" },
                        { "title": "Subject", "data": "Subject", "name": "Subject" },
                        { "title": "Contact", "data": "ContactId", "name": "ContactId" },                         
                        { "title": "Status ", "data": "CurrentStatus", "name": "CurrentStatus" },                        
                        { "title": "Team", "data": "Teamid", "name": "Teamid" },
                    ],
                });
            }
        }
        enabletemplateListVM.init();
    }

2 Answers 2

1

Use the code below for the column containing checkboxes.

Please note that I assumed closed tickets contain "Closed" in the status column, but change the code accordingly.

{
    "data": "Id", 
    "autoWidth": true,
    "render": function (data, type, full) {
        if(type === 'display'){
             var attrDisabled = '';

             // If ticket is closed
             if(full['CurrentStatus'] === 'Closed'){
                // Disable the checkbox
                attrDisabled = 'disabled';
             }

             data = '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '" ' + attrDisabled + '/>';
        }

        return data;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Without the complete code is very hard to help you. But if after the datatable is created you use something like:

jQuery('table').each(function(data) {
        console.log(data);
});

You can get the content of datatable and edit the checkbox visibility.

1 Comment

I just added the C# Code missing any help from you?

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.