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

Force read action to re-execute JS function assigned in .Data

2 Answers 387 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Adam King
Top achievements
Rank 1
Adam King asked on 22 Apr 2017, 03:56 PM

I'm updating my dropdown's datasource by calling   DDL.data("kendoDropDownList").dataSource.read();

This partially works, it executes the server side read event, but it does not execute the JS function which should dynamically get the parameters for the server side read event. The function assigned in .Data [see below] (GetAllDescriptorsData) only executes once - when the page loads, it does not re-execute when . call read() [see above]. 

My question is, How can I force a read and get new parameters?

 @(Html.Kendo().DropDownList()
                        .Name(YearDescriptorID)
                          .DataSource(source =>
                          {
                              source.Read(read =>
                              {
                                  var IsSpouse = Model.IsSpouse ? "1" : "0";
                                  read.Action("GetAllDescriptors", "Income").Data("GetAllDescriptorsData("+ Model.PersonalKey + "," + IsSpouse + ")");
                              
                              })
                               .ServerFiltering(true);
                          })
                        .AutoBind(false)
                        .DataTextField("DisplayText")
                        .DataValueField("IncomeKey")
                        .Events(e =>
                        {
                            e.Change("onChangeYearDescriptor");
                            e.DataBound("onDataboundYearDescriptor");
                        })
                )

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Tsvetanov
Telerik team
answered on 25 Apr 2017, 11:25 AM
Hello Adam,

The reason for the observed is the fact, that when used with parenthesis in the Data() method:
Data("GetAllDescriptorsData(" + Model.PersonalKey + "," + IsSpouse + ")")

the â€‹GetAllDescriptorsData() will be evaluated only once, initially and the returned value from that function fill be used as parameter for each Read call.

In order to call the GetAllDescriptorsData() â€‹with each Read action you will need to pass only the name of the function:
read.Action("GetAllDescriptors", "Income").Data("GetAllDescriptorsData");

Note, that if you need to pass parameters from the Model in this case, you will need to retrieve them directly in the â€‹GetAllDescriptorsData() function.

Regards,
Veselin Tsvetanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Adam King
Top achievements
Rank 1
answered on 25 Apr 2017, 02:51 PM
Thanks, that worked.
Tags
DropDownList
Asked by
Adam King
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Adam King
Top achievements
Rank 1
Share this question
or