In the popup editor, I only want to change their favorites not others, and the popup editor is implemented as checkboxes list, just like attachment picture2. The checkboxes list is initialized in the edit event of the gird. In the grid edit event, I have the following code:
edit: function (e) {
$("#fruitLists").css({ 'overflow-y': 'scroll', 'width': '280px', 'height': '170px' });
var checkboxes = '';
var fruitArray = e.model.fids.split(",");
var data = that.fruitDataSource.data();
for (var i = 0; i < data.length; i++) { //generate checkboxes list
var checked = fruitArray.indexOf(data[i].id + '') > -1 ? "checked" : "";
checkboxes += "<input type=\"checkbox\" name=\"fruitIdent\" value=\"" + data[i].id + "\" " + checked + " />" + data[i].name + "<br />\n";
}
$("#fruitLists").html(checkboxes);
e.container.find(".k-button.k-button-icontext.k-primary.k-grid-update").click(function () {
var checkedItems = [];
$("input[name='fruitIdent']:checked").each(function () { checkedItems.push($(this).val()); });
e.model.fids = checkedItems.join();
//update favorite fruits...
$("#grid").data("kendoGrid").saveRow();
});
},
My template for popup editor:
<div class="k-edit-form-container" id="popEditor">
<script id="popup_editor" type="text/x-kendo-template">
<div id="fruitLists" style="margin-left:35px">
</div>
</script>
</div>
And the schema for students list:
model: {
id: "id",
fields: {
id: { type: "number", nullable: false, editable: false }, //headmap
name: { type: "string", nullable: true },
favorits: { type: "string", nullable: true },
fids: { type: "string", nullable: true },
},
},
The curious is that, each time I click the Update button, it always trigger data source - transport's create event, not update event. Why? I searched this forum, many guys says that it is because the schema has no id or the popup UI has no id, but even I added the id field, only create event is fired with a null model.
Why my approach does not work? Is there any solution? Thansk.
11 Answers, 1 is accepted
The create transport of the DataSource will trigger when the saved record does not have an ID. I see that you have defined the ID in the schema configuration, but could you please confirm that each of the dataItems in the dataSource has an "id" field with unique value different from null or undefined?
Regards,
Alexander Valchev
Telerik
What I'm confused is that, even after I added the id field in the popup template:
<div class="k-edit-label">
<label for="id">id</label>
</div>
<div class="k-edit-field">
<input type="text" class="k-input k-textbox" name="id" data-bind="value:id" />
</div>
When I click the Update button and it only trigger create event.
If the create transport fires that means that according to the DataSource the record is considered as newly created. This will happen when the record does not have a unique ID.
According to your reply each record has unique ID. We can verify this by hooking up to the save event of the Grid and execute the following code:
editable:
"popup"
,
save:
function
(e) {
console.log(e.model.isNew());
}
What is the console.log output in your case?
Looking forward to your reply.
Regards,
Alexander Valchev
Telerik
Hi Alexander,
The output for my case is false. Is that weird?
Yes this is unusual. Is it possible for you to provide a Kendo Dojo or sample project with mock data that isolates the issue? In this way I will be able to reproduce it locally and examine what exactly is going wrong.
Regards,
Alexander Valchev
Telerik
Hi, I'm experiencing the exact same situation. Do you have any update on this ?
Lorenzo
Hi, after some try I kind of figured out a workaround. The problem in my case seems the fact that the ID i a number. If i replace the key with a dummy ToString() of my Int32 key it works.
UPDATE
I figured out that if the ID is a number (in my case lineNum) and it is defined both as ID and in the fields the strange behavior occurs:for each update also a create is triggered.
If the ID is a string putting it both in ID and in the fields doesn't make any difference.
Now lineNum is only the ID and it works.
Lorenzo
Please provide a sample project where we can observe the behaviour. In this way we will be able to examine it in details and assist you further.
Regards,
Alexander Valchev
Telerik