Checkbox selection
Checkbox selection
The checkbox field created with add API method doesn't check the selected values got from the server[when clicked on
Edit button of editor]. Interestingly the checkbox field created using fields initialization option checks the selected values got from the server.
This works:
[code]
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": ".....",
"domTable": "....",
"idSrc": "id",
"fields": [
....
....
{
"label": "User type:",
"name": "usertype",
"type": "checkbox",
"separator": "|",
"ipOpts": [
{ "label": "Student", "value": "1" },
{ "label": "Proctor", "value": "2" }
]
}
], ....
...
});
[/code]
Below doesn't show check to selected values:
[code]
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": ".....",
"domTable": "....",
"idSrc": "id",
....
...
});
editor.on('onInitCreate', function () {
fnUserScreenFields();
}
editor.on('onInitEdit', function () {
fnUserScreenFields();
}
function fnUserScreenFields() {
editor.add({
"label": "First name:",
"name": "fname"
});
editor.add({
"label": "Middle name:",
"name": "mname"
});
editor.add({
"label": "Last name:",
"name": "lname"
});
editor.add({
"label": "User type:",
"name": "usertype",
"type": "checkbox",
"separator": "|",
"ipOpts": [
{ "label": "Student", "value": "1" },
{ "label": "Proctor", "value": "2" }
]
});
....
....
}
var table = $('#userlist').dataTable( {
....
});
[/code]
below is my trimmed json string:
[code]
{"sEcho":1,"iTotalRecords":"13","iTotalDisplayRecords":"13","aaData":[{"id":"102674","fname":"xyz",...,"usertype":"1|2"}, ...
[/code]
Please note in the json string "usertype":"1|2" is the separated list of values to check. The checkboxs are checked [in Edit form of editor] when field is initialized using fields initialization option but when I use the second approach using add method of api the checkboxs are not shown checked in edit form.
http://editor.datatables.net/fields/#checkbox
Any pointers why the second approach doesn't work?
Regards,
Mathew
Edit button of editor]. Interestingly the checkbox field created using fields initialization option checks the selected values got from the server.
This works:
[code]
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": ".....",
"domTable": "....",
"idSrc": "id",
"fields": [
....
....
{
"label": "User type:",
"name": "usertype",
"type": "checkbox",
"separator": "|",
"ipOpts": [
{ "label": "Student", "value": "1" },
{ "label": "Proctor", "value": "2" }
]
}
], ....
...
});
[/code]
Below doesn't show check to selected values:
[code]
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": ".....",
"domTable": "....",
"idSrc": "id",
....
...
});
editor.on('onInitCreate', function () {
fnUserScreenFields();
}
editor.on('onInitEdit', function () {
fnUserScreenFields();
}
function fnUserScreenFields() {
editor.add({
"label": "First name:",
"name": "fname"
});
editor.add({
"label": "Middle name:",
"name": "mname"
});
editor.add({
"label": "Last name:",
"name": "lname"
});
editor.add({
"label": "User type:",
"name": "usertype",
"type": "checkbox",
"separator": "|",
"ipOpts": [
{ "label": "Student", "value": "1" },
{ "label": "Proctor", "value": "2" }
]
});
....
....
}
var table = $('#userlist').dataTable( {
....
});
[/code]
below is my trimmed json string:
[code]
{"sEcho":1,"iTotalRecords":"13","iTotalDisplayRecords":"13","aaData":[{"id":"102674","fname":"xyz",...,"usertype":"1|2"}, ...
[/code]
Please note in the json string "usertype":"1|2" is the separated list of values to check. The checkboxs are checked [in Edit form of editor] when field is initialized using fields initialization option but when I use the second approach using add method of api the checkboxs are not shown checked in edit form.
http://editor.datatables.net/fields/#checkbox
Any pointers why the second approach doesn't work?
Regards,
Mathew
This discussion has been closed.
Replies
One option is to call the `set` function immediately after the add with the value you want set.
I'll have a look into adding more events for this. Thanks for flagging it up.
Regards,
Allan