I posted this in another thread (https://www.telerik.com/forums/how-to-disable-a-dropdownlist-in-a-row-when-another-dropdownlist-chooses-a-value) if you need more background but this is a new issue I've encountered so it deserves it's own thread in case someone else runs into it.
I have a grid very similar to the one in this example where I am using 3 different client templates to populate and bind 3 drop downs in my grid:
https://demos.telerik.com/aspnet-core/grid/editing-custom
My dropdowns are:
Category
Department
Configuration
I got this all working perfectly but then the client wanted to make Department an editable dropdown (either choose an option, or add a new one on the fly) so I converted the Department dropdownlist to a combobox
I then wrote an ajax call to add the new item to the database:
//e is the Department combobox
function addDepartment(e) {
var dept = new Object();
dept.DepartmentID = 0;
dept.DepartmentName = e.text();
$.ajax(
{
url: '@Url.Action("AddDepartment", "Wizard")',
type: 'GET',
dataType: "json",
data: dept,
contentType: 'application/json; charset=utf-8',
success: function (result) {
console.log("success");
//re-fetch the datasource so the combo has the newly added item in it with its new PK
this.dataSource.read();
//I tried forcing its selection like this but it didn't help
e.value(result.DepartmentID);
}
})
console.log("dept added");
}
Everything work the way it should, the record is saved to the db, the combobox has the newly added item selected but when you go to save the row, that newly added Department is not actually selected (you get an empty object posted to Controller). HOWEVER, if you first select another option from the Department combo then re-select the newly added item it 'sets' the state correctly to the new object and it gets posted to the Controller correctly. You can see in my script above I'm trying to force it to set the combo but that didn't work. Any ideas how to work around this?