DropDownListFor with ServerFiltering(true) and Initialization value

5 posts, 1 answers
  1. Robert Madrian
    Robert Madrian avatar
    163 posts
    Member since:
    Apr 2003

    Posted 19 Jun Link to this post

    Hello,

    If I use a DropDownListFor with ServerFiltering(true) there is no Initialization value - the DropDownList is always empty?

    I use this DropDownListFor in a grid Editor template:

    @(Html.Kendo().DropDownListFor(m => m.Mitglied_IDVerpaechter)
                                      .MinLength(1)
                                      .Height(400)
                                      .OptionLabel(" ").OptionLabelTemplate(" ")
                                      .DataTextField("Firmenbezeichnung")
                                      .Filter("contains")
                                      .NoDataTemplate("Keine Datensätze gefunden")
                                      .DataValueField("Mitglied_ID")
                                      .DataSource(dataSource =>
                                      {
                                          dataSource.Read(read => read.Action("Search", "Home", new { Area = "Mitglied" }).Type(HttpVerbs.Post))
                                              .ServerFiltering(true);
                                      })
                                      )

     

    How to use ServerFiltering and also have a initialization value?

    robert

     

  2. Dimitar
    Admin
    Dimitar avatar
    176 posts

    Posted 22 Jun Link to this post

    Hello Robert,

    I am attaching an ASP.NET Core solution, where a similar scenario to the one described is demonstrated (Kendo DropDownList inside a Grid editor template).

    With it, the DropDownList is correctly bound to the ViewModel. If you try to change the value of the dropdown, you will notice that the foreign key column of the Grid is also updated accordingly.

    In addition to the above, in the custom editor template, the initial value of the dropdown is set by using the DropDownList's value() method

    Regards,
    Dimitar
    Progress Telerik
    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. Robert Madrian
    Robert Madrian avatar
    163 posts
    Member since:
    Apr 2003

    Posted 28 Jun in reply to Dimitar Link to this post

    Hello,

    it seems that my Problem is a little bit different - if I open my edit form the dropdownlist is empty because it only display entries if a search term is inserted because it searches in a tabel with a lot of rows
    the dropdownlist is bound to a field of the model and is used in an grid edit template.
    but there is no value in the dropdownlist if I open the form - it seems I have to search for the value first?

    How to do this?

    robert

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    176 posts

    Posted 30 Jun Link to this post

    Hello Robert,

    You can use the DataSource's Data() method to send your search term as an additional parameter to the controller. Then you can query your database and build a collection depending on the value of the search term and return this collection as JSON. This way the DataSource of the widget will populate based on your special requirement. 

    You can review a similar scenario in the following DropDownList demo. You will notice that the second DropDownList passes as an additional parameter the value of the previous widget. Then in the controller, it performs a query, which filters the database result based on the additional parameter and returns it to the view. 

    I hope this helps you to resolve the issue.

    Regards,
    Dimitar
    Progress Telerik
    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.
  5. Robert Madrian
    Robert Madrian avatar
    163 posts
    Member since:
    Apr 2003

    Posted 02 Jul in reply to Dimitar Link to this post

    Hello Dimitar,

    I have solved it in a similar way - thanks for pointing me in the right direction...

    $("#grdPacht_" + berechtigungid).data("kendoGrid").bind("edit", function (e) {
                var model = e.model;
                var ddlMitglied_IDPaechter = $("#Mitglied_IDPaechter").getKendoDropDownList();
                var ddlMitglied_IDVerpaechter = $("#Mitglied_IDVerpaechter").getKendoDropDownList();
     
                GpdbHelpers.kendoDropDownList.reload("#Mitglied_IDPaechter", function () { return { text: model.Mitglied_IDPaechter } });
                GpdbHelpers.kendoDropDownList.reload("#Mitglied_IDVerpaechter", function () { return { text: model.Mitglied_IDVerpaechter } });
     
                ddlMitglied_IDPaechter.bind("filtering", function (e) {
                    if (e.filter.value) {
                        GpdbHelpers.kendoDropDownList.reload("#Mitglied_IDPaechter", function() { return { text: e.filter.value } });
                    }
                });
                ddlMitglied_IDVerpaechter.bind("filtering", function (e) {
                    if (e.filter.value) {
                        GpdbHelpers.kendoDropDownList.reload("#Mitglied_IDVerpaechter", function () { return { text: e.filter.value } });
                    }
                });
            });

     

Back to Top