I have a field in my datasource who's value from the server is a 'Y' or a 'N'. I need to display that string value on the grid. When editing the value, I need to show a checkbox, checked if value == 'Y'.
There are 2 ways I can try to solve this problem, as I can tell, but I have problems/questions with each approach.
1. I can change the data model by making the field of type boolean, ie:
model: {
fields: {
"myFlag": { type: 'boolean"}
}}
, then changing the template of the column template like so: ` template: "#= (myFlag) ? 'Y' : 'N'"
This gets my desired UI result. However, all of my records on the grid display 'N', even though most of the records have 'Y' as their myFlag value. So therefore, how do I tell the datasource that 'Y' is true and 'N' is false? Furthermore, why does my grid currently treat myFlag as false when myFlag does indeed have a string value in it, which should equate to true.
2. The other approach is to leave my data source alone and just build a custom editor. However, most tutorials out there use a template to show a checkbox. I don't want to do that; I want to display "Y/N", and only render the checkbox when editing. I do not see any examples out there with this configuration. Here is my current editor for this checkbox:
editor: function (container, options) {
var value = options.model[options.field];
$('<input required name="' + options.field + '" type="checkbox" data-bind="checked:('+options.field + '==\'Y\')" />')
.appendTo(container)
}
note, i've also tried setting the html attribute 'checked' to no avail.