Checkboxes on an Editor Form - checkbox state is flipped
Checkboxes on an Editor Form - checkbox state is flipped
Hi folks, I'm using the DataTables.net Editor. One of my fields is a checkbox, and I define it as such:
[code]
{
"dataProp": "IsAssociated",
"label":"Is assigned",
"name":"IsAssociated",
"type": "checkbox",
"ipOpts": [
{
"label": "",
"value": ""
}
],
"separator": ""
},
....
[/code]
I'm loading my DataTable from an AJAX source. The JSON data coming across for this checkbox field is transmitted as "True" or "False" (not "1" or "0"). This is what my WCF service serializes a boolean as.
My problem is that in my Editor form, False values are giving the checkbox a checkmark, and True values do NOT have a checkmark. Can anyone tell me what might be wrong with my field declaration above? Or where else I might investigate?
From the docs, it looks like there can be multiple checkboxes that are mutually exclusive and used like radio buttons, but that's not what I'm trying to do. I just need to represent a boolean value. Thanks in advance!
Edit: Allan, we're doing a lot with DataTables.net, the Editor, and .NET (particularly with WCF services). Would you be interested in posting any of our basic examples for the .NET world? If so, let me know at rob _at_ ironhorsesoftware.com.
[code]
{
"dataProp": "IsAssociated",
"label":"Is assigned",
"name":"IsAssociated",
"type": "checkbox",
"ipOpts": [
{
"label": "",
"value": ""
}
],
"separator": ""
},
....
[/code]
I'm loading my DataTable from an AJAX source. The JSON data coming across for this checkbox field is transmitted as "True" or "False" (not "1" or "0"). This is what my WCF service serializes a boolean as.
My problem is that in my Editor form, False values are giving the checkbox a checkmark, and True values do NOT have a checkmark. Can anyone tell me what might be wrong with my field declaration above? Or where else I might investigate?
From the docs, it looks like there can be multiple checkboxes that are mutually exclusive and used like radio buttons, but that's not what I'm trying to do. I just need to represent a boolean value. Thanks in advance!
Edit: Allan, we're doing a lot with DataTables.net, the Editor, and .NET (particularly with WCF services). Would you be interested in posting any of our basic examples for the .NET world? If so, let me know at rob _at_ ironhorsesoftware.com.
This discussion has been closed.
Replies
[code]
{
"dataProp": "IsAssociated",
"label":"Is assigned",
"name":"IsAssociated",
"type": "checkbox",
"ipOpts": [
{
"label": "", //leave this blank because I'm already using 'Is assigned' as my label.
"value": "1" //1 will check the checkbox if the value is True.
}
],
"separator": ""
},
....
[/code]
This does lead to one potential problem. On the JSON postback, the value of IsAssociated will be in an array with one element. If you don't want to bend your web service to accommodate DataTables.net, you can reassign the value before the Editor calls back to the server. In the Editor initialization code, I changed the following:
[code]
var myEditor = new $.fn.dataTable.Editor({
"ajax": function (method, url, data, successCallback, errorCallback) {
data.data.IsAssociated = data.data.IsAssociated[0];
... more code ...
},
...
[/code]
Allan or anyone else, can you confirm that this is the correct way to accomplish this?
Regards,
Allan