How to add checkboxes based on JSON values?

How to add checkboxes based on JSON values?

webdev2111webdev2111 Posts: 4Questions: 0Answers: 0
edited January 2013 in General
I am new to datatables and I am truing to add checkboxes to the table being generated based on the values in the JSON.
I want to display checkboxes for the read, write, execute and admin values.
If the value is equal to 1 , I want the checkbox to be checked.
And if 0 checkboxes unchecked.

I have the following code to generate the table. How can i enable that in datatables?

Javascript



$(document).ready(function() {
var oTable = $('#example').dataTable( {
"sScrollY": "500px",
"bPaginate": false,
"bProcessing": true,
"sAjaxSource": "sources/sample.json"
} );


} );



HTML






Browser
Read
Write
Execute
Admin








JSON


{ "aaData": [
["Trident","0","0","0","1"],
["Trident","0","1","0","0"],
["Trident","0","0","1","1"],
["Trident","0","0","1","1"],
["Trident","0","0","1","1"],
["Trident","0","0","0","0"],
["Gecko","1","1","1","1"],
["Gecko","0","0","0","1"],
["Other browsers","1","0","0","U"]
] }

Replies

  • whoopeswhoopes Posts: 9Questions: 0Answers: 0
    You're looking for fnRowCallback http://datatables.net/usage/callbacks.

    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
    if (aData[8] = '1'){
    $('td:eq(8)', nRow).html(' ');
    }else{
    $('td:eq(8)', nRow).html(' ');
    }
    return nRow;
    }
This discussion has been closed.