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

DropDownListFor with ServerFiltering(true) and Initialization value

4 Answers 343 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 19 Jun 2017, 02:14 PM

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

 

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 22 Jun 2017, 11:59 AM
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.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 28 Jun 2017, 06:11 PM

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

0
Accepted
Dimitar
Telerik team
answered on 30 Jun 2017, 12:38 PM
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.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 02 Jul 2017, 09:01 AM

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 } });
                }
            });
        });

 

Tags
DropDownList
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Dimitar
Telerik team
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Share this question
or