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

Remote Datasource not Populating DropDownList

3 Answers 300 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Elliot
Top achievements
Rank 1
Elliot asked on 24 Apr 2013, 03:36 PM
I have the following code:
   <script type="text/javascript">
        $(function() {
            var url = urltogetdata;
            $("#products").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "name",
                dataSource: {
                    transport: {
                        read: {
                            url: url,
                            contentType:'application/javascript; charset=utf-8',
                            type:'GET',
                            dataType:'jsonp'
                        },
                        schema: {
                            data: "result"
                        }
                    }
                }
            });
        });
</script>
<asp:HiddenField ID="webServer" runat="server" />
 <asp:HiddenField ID="cred" runat="server" />
 <input id="products" style="width: 250px" />

When I hit the url directly an excerpt of the response is:
{"result":[{"name":"228 - Sal ","entityIdentifier":{"id":23}},{"name":"230 - Fitters Truck","entityIdentifier":{"id":24}},{"name":"2300 - Duane Agnew","entityIdentifier":{"id":20}}, etc....

When I run this the ddl just spins and nothing happens. Why?

Also, if I want to bind the dataTextField to name and the dataValueField to the entityIdentifiers id property how would I do this?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 24 Apr 2013, 04:46 PM
Hi Elliot,

I believe that the binding problem is connected with the Ajax configuration. Please try the following:
read: {
    url: url,
    type:'GET',
    dataType:'json'
},

Regarding your second question, I suggest you to try the following:
dataTextField: "name"
dataValueField: "entityIdentifiers.id"


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Elliot
Top achievements
Rank 1
answered on 24 Apr 2013, 05:56 PM
I am still having a problem.  I have tried:
            $("#products").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "entityIdentifiers.id",
                dataSource: {
                    transport: {
                        read: {
                            url: url,
                            type: 'GET',
                            dataType: 'json'
                        },
                        schema: {
                            data: function(response) {
                                return response.result;
                            }
                        }
                    }
                }
            });
which shows the kendo dropdown but doesnt populate it with any items.

I have got it populating with the following where r is a subset of what gets returned from the server:
            var r = {"result":[{"name":"228 - Sal ","entityIdentifier":{"id":23}},{"name":"230 - Fitters Truck","entityIdentifier":{"id":24}}]};
            $("#products").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "entityIdentifier.id",
                dataSource: r.result
            });

But cannot seem to get it working with remote data.  Any suggestions would be greatly appreciated.
0
Accepted
Elliot
Top achievements
Rank 1
answered on 24 Apr 2013, 07:53 PM
I feel a little stupid.  The issue was simply syntax.  I had the schema in the incorrect spot.  I have it working with:
            $("#products").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "entityIdentifier.id",
                dataSource: {
                    transport: {
                        read: {
                            dataType: 'json',
                            url: url
                        }
                    },
                    schema: {
                        data: "result"
                    }
                }
            });
Tags
DropDownList
Asked by
Elliot
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Elliot
Top achievements
Rank 1
Share this question
or