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

Client-Side syntax for Datasource with a parameter on Dynamic creation of DropDownList

1 Answer 134 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 17 Feb 2016, 03:17 PM

I'm having to dynamically create instances of the kenod dropdownlist and I have it working fine except I need to know what the equivalent syntax for defining the datasource.

 

Here is the razor server-side syntax:

 

@(Html.Kendo().DropDownList()
                        .Name("lineItemTypeCode")
                        .OptionLabel("..........")
                        .HtmlAttributes(new { style = "width:100%", @class = "itemTypeClass", required = "required" })
                        .DataValueField("Code")
                        .DataTextField("Name")
                        .DataSource(source => { source.Read(read => { read.Action("GetItemTypes", "RequestPONumber").Data("GetSelectedLocation"); }); })
      )

Action is GetItemTypes

Controller is RequestPONumber

Here is my client-side:

var newItemTypeDdl = $("#itemTypeddl" + poLinesCount).kendoDropDownList(
            {
                dataTextField: 'Name',
                dataValueField: 'Code',
                dataSource: ??????,
                optionLabel: "..........",
            });

 

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 19 Feb 2016, 11:18 AM
Hello Greg,

I answered to the support thread opened on the same subject. I would like to ask you continue the discussion in only one thread to avoid duplication. Thank you in advance.

As to the question, you can create a DataSource instance using the datasource of the initial dropdownlist. You can either get the URL and fetch the data again or just use it directly. I suppose that you wouldn't need to re-fetch it. In this case, the code will like something like this:
var dataSource = $("#lineItemTypeCode").data("kendoDropDownList").dataSource;
 
var newDS = new kendo.data.DataSource({
  data: new kendo.data.ObservableArray(dataSource.data())
});

If you still need to fetch the data, then you can just serialize the URL and use it in the dataSource creation:
var url = "@Url.Action("GetItemTypes", "RequestPONumber")";
 
//use the url in the datasource creation


Regards,
Georgi Krustev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Greg
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or