jeudi 24 septembre 2015

Bind Checkbox value dynamically from database using Jquery Datatables Plugin?

I am using Jquery Datatable plugin for displaying data. Here I have a column with checkbox which should be checked or unchecked according to the values from the database.ie if the value from the db is true checkbox should be checked and if value from db is false checkbox should be unchecked.

Here is what I have tried so far.

table = $("#dataTableMenuRole").dataTable({
        "ajax": {
            "url": "@Url.Action("LoadGridView", "MenuSettings")",                
            "method": "POST",
            "dataType": "json",
            "data": function (d) {
                d.roleId = $("#ddlRoles").val()
            }
        },
        columns: [
            { "data": "MenuName" },
            { "data": "CanAdd" }               

        ],            
        "bProcessing": true,
        "aoColumnDefs": [{
            "targets": 1,
            "bSortable": false,
            "mRender": function (data, type, full, meta) {
                return '<input type="checkbox" class="minimal" checked="'+data+'"/>'
            }
        }]
    });

The json returned from the db is

{"data":[{"MenuName":"Roles","CanAdd":true},{"MenuName":"Menu","CanAdd":true},{"MenuName":"ServiceTax","CanAdd":false}]}




Aucun commentaire:

Enregistrer un commentaire