I'm looking for an example of casting KendoUI DropDownList using remote data.
Specifically,
I have a dropdownlist for state. Once the state is selected, the dropdown list for city populates (based on the selection value of the state dropdown list). Once the city item is selected, the School dropdown is populated (based off both the state and city values). Seems simple enough...but
Please note:
//This example on cascading won't work for me because I'm not working with MVC or server-side to handle this
http://demos.kendoui.com/web/dropdownlist/cascadingdropdownlist.html
//I wired up the change event using this example, but did not have any luck
http://www.kendoui.com/forums/kendo-ui-web/dropdownlist/3-cascade-remote-dropdownlists.aspx
//This jsFiddle example is close to what I'm trying to do...but I'm not using oData and wasn't too sure
http://jsfiddle.net/krustev/xuZn9/
//I've seen other examples where the 2nd dropdownlist dataset actually has ALL values and is just filtered - this won't work because the sets are too large to load all at once.
//Here's the code for 2 of the 3 dropdownlists (figured if i could get 2 I could get 3), any help would be much appreciated.
<script type="text/javascript">
jQuery(document).ready(function () {
LoadStates(1);
LoadCities(70);
});
function LoadStates(pageLoad) {
var stateDataSource = [
{ stateName: "MA", stateValue: "1" },
{ stateName: "NH", stateValue: "2" },
{ stateName: "VT", stateValue: "3" }
];
var states = jQuery("#StateDropDown").kendoDropDownList({
optionLabel: "Select State...",
dataTextField: "stateName",
dataValueField: "stateValue",
dataSource: stateDataSource,
change: function () {
var stateId = this.value();
var ddl = jQuery("#CityDropDown").data("kendoDropDownList");
if (stateId) {
LoadCities(stateId);
ddl.enable();
} else {
ddl.enable(false);
}
}
});
//if first time on page, select 1st option in dropdown
var ddlStates = states.data("kendoDropDownList");
if (pageLoad == 1) {
ddlStates.select(1);
}
}
function LoadCities(stateId) {
//Load all the cities based on a particular state
var cities = $("#CityDropDown").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
optionLabel: "Select City...",
dataSource: {
transport: {
read: {
dataType: "json",
url: ".../api/digital/GetAllCities/" + stateId,
cache: false
}
},
schema: {
//This works correctly, the Web API returns the following when passed in state ID 1 for MAy
// {"Table":[{"Value":111,"Text":"Boston"},{"Value":222,"Text":"Cambridge"},...{"Value":333,"Text":"Lexington"}]}
data: "Table"
}
}
});
//Always set the list to the first option unless on initial page load...TODO
var ddlCities = cities.data("kendoDropDownList");
ddlCities.select(0);
}
</script>
<input id="StateDropDown" />
<input id="CityDropDown" />
<input id="SchoolDropDown" disabled="disabled" />
Specifically,
I have a dropdownlist for state. Once the state is selected, the dropdown list for city populates (based on the selection value of the state dropdown list). Once the city item is selected, the School dropdown is populated (based off both the state and city values). Seems simple enough...but
Please note:
//This example on cascading won't work for me because I'm not working with MVC or server-side to handle this
http://demos.kendoui.com/web/dropdownlist/cascadingdropdownlist.html
//I wired up the change event using this example, but did not have any luck
http://www.kendoui.com/forums/kendo-ui-web/dropdownlist/3-cascade-remote-dropdownlists.aspx
//This jsFiddle example is close to what I'm trying to do...but I'm not using oData and wasn't too sure
http://jsfiddle.net/krustev/xuZn9/
//I've seen other examples where the 2nd dropdownlist dataset actually has ALL values and is just filtered - this won't work because the sets are too large to load all at once.
//Here's the code for 2 of the 3 dropdownlists (figured if i could get 2 I could get 3), any help would be much appreciated.
<script type="text/javascript">
jQuery(document).ready(function () {
LoadStates(1);
LoadCities(70);
});
function LoadStates(pageLoad) {
var stateDataSource = [
{ stateName: "MA", stateValue: "1" },
{ stateName: "NH", stateValue: "2" },
{ stateName: "VT", stateValue: "3" }
];
var states = jQuery("#StateDropDown").kendoDropDownList({
optionLabel: "Select State...",
dataTextField: "stateName",
dataValueField: "stateValue",
dataSource: stateDataSource,
change: function () {
var stateId = this.value();
var ddl = jQuery("#CityDropDown").data("kendoDropDownList");
if (stateId) {
LoadCities(stateId);
ddl.enable();
} else {
ddl.enable(false);
}
}
});
//if first time on page, select 1st option in dropdown
var ddlStates = states.data("kendoDropDownList");
if (pageLoad == 1) {
ddlStates.select(1);
}
}
function LoadCities(stateId) {
//Load all the cities based on a particular state
var cities = $("#CityDropDown").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
optionLabel: "Select City...",
dataSource: {
transport: {
read: {
dataType: "json",
url: ".../api/digital/GetAllCities/" + stateId,
cache: false
}
},
schema: {
//This works correctly, the Web API returns the following when passed in state ID 1 for MAy
// {"Table":[{"Value":111,"Text":"Boston"},{"Value":222,"Text":"Cambridge"},...{"Value":333,"Text":"Lexington"}]}
data: "Table"
}
}
});
//Always set the list to the first option unless on initial page load...TODO
var ddlCities = cities.data("kendoDropDownList");
ddlCities.select(0);
}
</script>
<input id="StateDropDown" />
<input id="CityDropDown" />
<input id="SchoolDropDown" disabled="disabled" />