This is a migrated thread and some comments may be shown as answers.

How to select item from drop downlist?

1 Answer 73 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Laksh
Top achievements
Rank 1
Laksh asked on 26 Aug 2014, 07:49 PM

Im getting the following json response from the server.

[{"TaxYear":2014,"IsCurrentFlag":false},{"TaxYear":2013,"IsCurrentFlag":true},{"TaxYear":2012,"IsCurrentFlag":false}]

How do I set the selected item based on "IsCurrentFlag" where "IsCurrentFlag  == true" ?

Below is my code to Create DataSource and Set the DropDownList.

var taxYearsDS: kendo.data.DataSource = createDataSource("GetYears");
 
var $taxYears: JQuery = $("#taxYears");
    $taxYears.kendoDropDownList({
        dataSource: taxYearsDS,
        dataTextField: "TaxYear",
        dataValueField: "TaxYear"               
    });
 
    function createDataSource(action: string): kendo.data.DataSource {
        var schema: kendo.data.DataSourceSchema;
 
        return new kendo.data.DataSource({
            type: type,
            transport: {
                read: {
                    url: svcUrl + "/myapi/" + action,
                    dataType: "json"
                },
            },
            schema: schema,
            serverFiltering: false
        });
    }


1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 28 Aug 2014, 08:41 AM
Hello Laksh,

I will suggest you wire the dataBound event of the widget and use its select method with predicate:
function dataBound() {
    this.select(function(dataItem) {
        return dataItem.isCurrentFlag === true;
    });
}

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Laksh
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or