Hi, I'm wondering about a particular behavior with the Combobox.
I have a generic combobox (for people) in an editor template (basic code):
A little backstory about what I'm trying to do: I want to be able to use the combobox to load only partial data from the datasource (since all data can be too much). This is not a big deal if you just want to use the combo to search, but I also want to use it to show a single selected person (for example when editing a row in a grid, I want the combobox to load only the single person by id).
I thought I had a somewhat functional solution where I would use the combobox._initial field to see if the combobox should initially pull in the person by id. The "getData" function was similar to this:
On the backend I would either load a single person by id, or search by text depending on what is passed.
When I use this in a MVC view (using HtmlHelper.EditorFor) it works fine, but when I use it in a grid (popup edit window) I am getting a different behavior. The _initial field value is not set to that of the grid dataItem; it is set to either 0 or blank depending on whether my property is nullable or not. It appears that the grid tries to setup the window editor form before binding the dataItem to it. So initially when the combobox tries to load data from the datasource, it can't know the id to pass.
How can I determine the PersonId in this case?
I have a generic combobox (for people) in an editor template (basic code):
@model
long
?
@(Html.Kendo().ComboBoxFor(m => m)
.DataTextField(
"DisplayName"
)
.DataValueField(
"PersonId"
)
.Filter(FilterType.Contains)
.DataSource(
source =>
source.Read(read => read.Action(
"Search"
,
"PersonController"
)
.Data(
"getData"
)).ServerFiltering(
true
))
)
A little backstory about what I'm trying to do: I want to be able to use the combobox to load only partial data from the datasource (since all data can be too much). This is not a big deal if you just want to use the combo to search, but I also want to use it to show a single selected person (for example when editing a row in a grid, I want the combobox to load only the single person by id).
I thought I had a somewhat functional solution where I would use the combobox._initial field to see if the combobox should initially pull in the person by id. The "getData" function was similar to this:
var
combo = $(selector).data(
'kendoComboBox'
);
if
(combo._initial !=
''
&& !combo.hasLoadedInitial) {
combo.hasLoadedInitial =
true
;
return
{ id: combo._initial };
}
else
return
{ text: combo.input.val() };
On the backend I would either load a single person by id, or search by text depending on what is passed.
When I use this in a MVC view (using HtmlHelper.EditorFor) it works fine, but when I use it in a grid (popup edit window) I am getting a different behavior. The _initial field value is not set to that of the grid dataItem; it is set to either 0 or blank depending on whether my property is nullable or not. It appears that the grid tries to setup the window editor form before binding the dataItem to it. So initially when the combobox tries to load data from the datasource, it can't know the id to pass.
How can I determine the PersonId in this case?