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

2 posts, 0 answers
  1. Brooke
    Brooke avatar
    1 posts
    Member since:
    Nov 2017

    Posted 10 Jan Link to this post

    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).
  2. Stefan
    Admin
    Stefan avatar
    1713 posts

    Posted 12 Jan Link to this post

    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.
Back to Top