How to select default value on loading dynamic kendo dropdownlist
//calling the below function to get the weekendingdates from database using ajax call
//calling the below function to bind the data to kendo dropdown as datasource
ex: function BindDropDown() {
WeekDates = new kendo.data.DataSource({
data: WeekDates,
batch: true,
schema: {
model: {
fields: {
WeekendingValue: { type: "string" }
}
},
}
});
}
//kendo dropdown with datasource
ex: $("#products").kendoDropDownList({
filter: "contains",
optionLabel: "Select WeekEndingDate",
dataTextField: "WeekendingValue",
dataValueField: "WeekendingValue",
virtual: {
itemHeight: 26,
valueMapper: function (options) {
}
},
dataSource: WeekDates
}).data("kendoDropDownList").select(1);
In the above data("kendoDropDownList").select(1) is used to select the value at index 1 by default In this case as Iam bringing the weekendingdates in desc order,so the last weekendingdate will be first in order and selected by default.
ex: function GetWeekEndingDates() {
$.ajax({
type: 'GET',
url: "WS_Equipment.asmx/GetWeekendingDate",
dataType: "json",
success: function (jsonData) {
var i = JSON.parse(JSON.stringify(jsonData));
if (jsonData != null) {
WeekDates = i.WeekEndingDates;
LastWeekDate = i.LastWeekEndingDate;
BindDropDown();
}
},
error: function (error) {
alert(error.responseText)
}
});
}
$.ajax({
type: 'GET',
url: "WS_Equipment.asmx/GetWeekendingDate",
dataType: "json",
success: function (jsonData) {
var i = JSON.parse(JSON.stringify(jsonData));
if (jsonData != null) {
WeekDates = i.WeekEndingDates;
LastWeekDate = i.LastWeekEndingDate;
BindDropDown();
}
},
error: function (error) {
alert(error.responseText)
}
});
}
ex: function BindDropDown() {
WeekDates = new kendo.data.DataSource({
data: WeekDates,
batch: true,
schema: {
model: {
fields: {
WeekendingValue: { type: "string" }
}
},
}
});
}
//kendo dropdown with datasource
ex: $("#products").kendoDropDownList({
filter: "contains",
optionLabel: "Select WeekEndingDate",
dataTextField: "WeekendingValue",
dataValueField: "WeekendingValue",
virtual: {
itemHeight: 26,
valueMapper: function (options) {
}
},
dataSource: WeekDates
}).data("kendoDropDownList").select(1);
In the above data("kendoDropDownList").select(1) is used to select the value at index 1 by default In this case as Iam bringing the weekendingdates in desc order,so the last weekendingdate will be first in order and selected by default.
Comments
Post a Comment