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

3 posts, 1 answers
  1. Adam King
    Adam King avatar
    31 posts
    Member since:
    May 2010

    Posted 22 Apr 2017 Link to this post

    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. Answer
    Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1041 posts

    Posted 25 Apr 2017 Link to this post

    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.
  3. Adam King
    Adam King avatar
    31 posts
    Member since:
    May 2010

    Posted 25 Apr 2017 in reply to Veselin Tsvetanov Link to this post

    Thanks, that worked.
Back to Top