如何在jquery.datatable中显示复选框
How to show checkboxes in jquery.datatables?
我正在使用datatable,我有以下代码来生成表。我想为读、写、执行和管理值显示复选框。如果值等于1,我希望复选框被选中。如果0个复选框未选中
Javascript<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"sScrollY": "500px",
"bPaginate": false,
"bProcessing": true,
"sAjaxSource": "sources/sample.json"
} );
} );
</script>
HTML <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th width="20%">Browser</th>
<th width="25%">Read</th>
<th width="25%">Write</th>
<th width="15%">Execute</th>
<th width="15%">Admin</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
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"]
] }
我能够得到它的工作使用数据渲染器
$(document).ready(function () {
var oTable = $('#example').dataTable({
"aoColumnDefs": [{
"aTargets": [0],
//"mData": "download_link",
"mRender": function (data, type, full) {
if (data == "Gecko") {
return '<a href="' + data + '">' + data + ' Download Gecko</a>';
} else {
return '<a href="' + data + '">' + data + ' Download</a>';
}
}
}, {
"aTargets": [1],
//"mData": "download_link",
"mRender": function (data, type, full) {
if (data == "1") {
return '<input type='"checkbox'" checked value="' + data + '">';
} else {
return '<input type='"checkbox'" value="' + data + '">';
}
}
}, {
"aTargets": [2],
//"mData": "download_link",
"mRender": function (data, type, full) {
if (data == "1") {
return '<input type='"checkbox'" checked value="' + data + '">';
} else {
return '<input type='"checkbox'" value="' + data + '">';
}
}
}, {
"aTargets": [3],
//"mData": "download_link",
"mRender": function (data, type, full) {
if (data == "1") {
return '<input type='"checkbox'" checked value="' + data + '">';
} else {
return '<input type='"checkbox'" value="' + data + '">';
}
}
}, {
"aTargets": [4],
//"mData": "download_link",
"mRender": function (data, type, full) {
if (data == "1") {
return '<input type='"checkbox'" checked value="' + data + '">';
} else {
return '<input type='"checkbox'" value="' + data + '">';
}
}
}],
"bFilter": false,
"sScrollY": "500px",
"bPaginate": false,
"bProcessing": true,
"sAjaxSource": "sources/sample.json"
});
});
相关文章:
- (php/jquery)根据另一个选中的复选框值隐藏和显示复选框
- 根据文本字段中的用户输入隐藏/显示复选框
- Javascript 显示复选框值与值中的空格中断
- 如何在 angularjs 中单击按钮时显示复选框列表
- 在单击按钮时在特定行中显示复选框
- 选择组合框后显示复选框
- 使用vuejs显示复选框选中的行
- 如何在提交前显示复选框值,或者在勾选时显示复选框本身
- 如何在数字框中显示复选框和下拉列表的乘积
- 选中单选框后显示复选框和文本字段的列表
- 如何使用jquery ajax显示复选框列表中的项目
- 单击按钮时显示复选框
- 正在寻找与don'“不再显示”复选框
- 使用字体显示复选框
- 显示'复选框仅在选中特定复选框时使用
- 滑动显示复选框
- 在angularjs中,如何在数据库中设置值时显示复选框为已选中
- 尝试在选择表单中的七个值之一时显示复选框
- 在同一页面上的表中显示复选框和表单数据
- 用JavaScript显示复选框的结果