I have a grid with custom editors and they are bound to the grid as such.
columns.Bound(x => x.Parent).EditorTemplateName("ParentEditor").ClientTemplate("#= Parent === undefined || Parent === null ? '' : parentTemplate(Parent)#");
columns.Bound(x => x.Child).EditorTemplateName("ChildEditor").ClientTemplate("#= Child === undefined || Child === null ? '' : childTemplate(Child)#");
The two editor templates look like this:
@model List<ParentViewModel>
@(Html.Kendo()
.MultiSelectFor(m => m)
.DataTextField("Name")
.DataValueField("Id")
.Placeholder("Select one or more parents")
.AutoBind(true)
.TagMode(MultiSelectTagMode.Multiple)
.DataSource(source =>
{
source
.Read(read =>
{
read.Action("GetParent", "Lookup");
});
})
.Events(events => events.Change("onParentChange"))
)
@model List<ChildViewModel>
@(Html.Kendo()
.MultiSelectFor(m => m)
.DataTextField("Name")
.DataValueField("Id")
.Placeholder("Select one or more children")
.AutoBind(true)
.TagMode(MultiSelectTagMode.Multiple)
.DataSource(source =>
{
source
.Read(read =>
{
read.Action("GetChild", "Lookup").Data("getCurrentParents");
})
;
})
)
The UI is properly populating when the grid loads and looks like this:
Coumn Parent|Column Child
A |A1
B |B1, B2
When the user edits the row and removes item B from Column Parent, this code is invoked (which I got from Kendo UI Snippet | Kendo UI Dojo)
function onParentChange(e) {
var selectedonParentChange = this.value();
let dataItems = e.sender.dataItems();
var multiSelect = $("#Child").data("kendoMultiSelect");
var value = multiSelect.value();
multiSelect.dataSource.filter(getFilterObj(dataItems));
multiSelect.dataSource.filter({}); // Adding or removing has no effect
multiSelect.refresh();
multiSelect.value(value);
console.log("Second value: " + multiSelect.value());
var dataSource = multiSelect.dataSource;
dataSource.read();
}
function getFilterObj(dataItems){
let filtObj = {
logic: "or",
filters: [],
};
if(dataItems.length > 0){
for (var i = 0; i < dataItems.length; i++) {
filtObj.filters.push({
field: "ParentId",
operator: "eq",
value: dataItems[i].Id
});
}
} else {
filtObj.filters.push({
field: "ParentId",
operator: "eq",
value: ""
});
}
return filtObj;
}
After the code runs, the UI looks like this:
Coumn Parent|Column Child
A |A1
So far so good. The problem is that when the user hits save this ends up on the Network in the form data:
Parent[0].Id: ParentIdA
Parent[0].Name: A
Child[0].Id: ChildId1
Child[0].Name: A1
Child[0].ParentId: ParentIdA
Child[1].Id: ChildId2
Child[1].Name: B1
Child[1].ParentId: ParentIdB
Child[2].Id: ChildId3
Child[2].Name: B2
Child[2].ParentId: ParentIdB
Kendo Version: 2024.4.1112