I have a scenario where I am using the popup editor and a custom template to edit items in the grid. The template has all of the fields that are part of the datasource that is bound to the grid as well as some additional fields that are not a part of the datasource. In order to submit the extra data, I am doing the following:
1. Setting data-skip=true attribute on the elements that are not bound to to the datasource to prevent binding. For example:
<input
type="radio"name="radio_test_a"id="radio_test1"value="1"data-skip="true"checked>Yes
<input
type="radio"name="radio_test_a"id="radio_test2"value="0"data-skip="true">No
2. In my update function I am getting the extra data and adding it to the ajax data parameter along with the model. For example:
update:
function(options) {
var roles_obj={};
$('#extra_data
input[type=radio]').each(function(){
if($(this).is(":checked")){
roles_obj[$(this).attr('name')]=$(this).val();
}
});
$.ajax({
url:
"api/users/update",
type: "POST",
dataType:
"JSON",
data: {
id:
kendo.stringify(options.data.id),
data:
JSON.stringify({
model:
options.data,
roles:
roles_obj
})
},
success: function
(result) {
options.success(result);
}
//remainder omitted for brevity
3. In the grid edit function, setting the model 'dirty' when the non-data bound fields are changed to ensure the update function is triggered. For example:
$('#extra_data
input[type=radio]').change(function() {
var ds = grid.dataSource;
var item =
ds.getByUid(e.model.uid);
item.dirty = true;
})
My question is this: While the above works and allow me to submit the extra data that is not part of the datasource, I am asking if this solution is tenable or if there is another approach that would be recommended?
Please let me know if further information is needed if it is not clear what I am asking.