MVC Kendo Grid read.Action().Data(function) not called on a forced datasource.read()

1 Answer 4323 Views
Data Source
Brooke
Top achievements
Rank 1
Brooke asked on 10 Jan 2018, 10:09 PM

This is Kendo ASP MVC though the question is about DataSource.

Our code has two dropdowns.  When the `onchange()` for the first fires it calls `$("#classDropDown").data("kendoDropDownList").dataSource.read();` to force the second one to update.

<%: Html.Kendo().DropDownList().Name("speciesDropDown")
          .DataTextField("Text")
          .DataValueField("Value")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetNLSSpecies", "RefData").Data("noFilters");
              });
          })
          .HtmlAttributes(new { style = "width: 50%" })
          .Filter(FilterType.Contains)
%>
...
<%: Html.Kendo().DropDownList().Name("classDropDown")
          .DataTextField("Text")
          .DataValueField("Value")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetClassData", "RefData").Data("mergeData()");
              });
          })
          .HtmlAttributes(new { style = "width: 50%" })
          .Filter(FilterType.Contains)
%>


Elsewhere ...

$('#speciesDropDown').on('change', function (event) {
    ...
    $("#classDropDown").data("kendoDropDownList").dataSource.read();
}


The `mergeData()` function is called to provide data from the Javascript to the server.  The **problem** is that because I'm calling this as a function it is **NOT** called during the `dataSource.read()`.  But it is called initially when the page first loads.  

Obviously I could change this to `mergeData` (ie. not a function) but it is the simplest case.  I'm actually trying to pass arguments, something like:

.Data("mergeData('getSpeciesDropdownObj','getShownOrRequired(\"OtherClass\")')")


This seems like a bug to me.  Does it to you?  

I originally posted this at https://stackoverflow.com/questions/48087808/mvc-kendo-grid-read-action-datafunction-not-called-on-a-forced-datasource-re and had a conversation about though the question didn't really get answered.  (I have since been given a login so I can post here).

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 Jan 2018, 09:40 AM
Hello, Brooke,

Thank you for the details.

The described result is expected because the Data method is expecting a string name leading to the function. Passing a function when the Grid is expecting the name of the function is not supported as it differs from the expected value of the Data method:

https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-send-values-to-my-action-method-when-binding-the-grid

The suggestions provided in StackOverflow are valid approaches which can be taken in this scenario.

Also, as the DropDown seems like cascading DropDowns, please check if the built-in cascading functionality is an option:

https://demos.telerik.com/aspnet-mvc/dropdownlist/cascadingdropdownlist

Let me know if you need additional information on this matter.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Data Source
Asked by
Brooke
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or