How to disable a checkbox in Editor?
How to disable a checkbox in Editor?
I've been trying to create a disabled checkbox in Editor but keep failing. I can always click inside the checkbox and change its value no matter which permutations of attributes and options I've tried. I've also modified one of your examples on http://live.datatables.net/rotivole/3/edit but get the same results. (I don't know if I broke anything by modifying that. Sorry, if I did.) I reduced the table to five people, added a 'Y' or a 'N' to the data and added my checkbox definition to Editor and DataTables but no matter what combination of attributes or options I tried, I could always click within the checkbox and change its value.
disabled:true
disabled:'true'
disabled:'disabled'
onclick:'return false';
etc...
$(document).ready(function() {
//$.fn.dataTable.render.moment("M/D/YYYY");
var editor = new $.fn.dataTable.Editor({
table: "#example",
fields: [
{
label: 'Name:',
name: 'name'
},
{
label: 'Position:',
name: 'position'
},
{
label: 'Office:',
name: 'office'
},
{
label: 'Age:',
name: 'age',
attr:{
class:'aNumericField2',
type:'number',
maxlength:13,
min:'0',
max:'99999999',
step:'0.01'
}
},
{
label: 'Start date:',
name: 'start_date',
type: 'datetime',
format: 'YYYY/M/D'
},
{
label: 'Salary:',
name: 'salary'
},
{
label: 'Alive',
name: 'alive',
type: 'checkbox',
separator: '',
unselectedValue: 'N',
options: [{ label: '', value: 'Y' }],
attr: {disabled:true}
}
]
});
$("#example").DataTable({
dom: "Bfrtip",
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'age' },
{ data: 'start_date' },
{ data: 'salary' },
{ data: 'alive' }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
});
$('#example').on('click', 'tbody tr td', function() {
editor.inline(this);
});
});
This question has an accepted answers - jump to answer
Answers
According to the
checkbox
docs it doesn't have anattr
option. I think you will want to setup your checkbox more like this example:https://editor.datatables.net/examples/api/checkbox.html
And use Datatables to enable to disable it.
Kevin