How to add checkboxes based on JSON values?
How to add checkboxes based on JSON values?
webdev2111
Posts: 4Questions: 0Answers: 0
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"]
] }
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"]
] }
This discussion has been closed.
Replies
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
if (aData[8] = '1'){
$('td:eq(8)', nRow).html(' ');
}else{
$('td:eq(8)', nRow).html(' ');
}
return nRow;
}