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

DropDownList server filtering - do I need additional action?

16 Answers 1862 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 09 Jun 2015, 09:51 PM

I am trying to do this

http://demos.telerik.com/aspnet-mvc/dropdownlist/serverfiltering

 It looks like I dont have to have any special action in the controler

This is my ddl

 

@(Html.Kendo().DropDownList()
                  .Name("commonCreditorID")
                .DataTextField("CREDITOR_NAME")
                .DataValueField("COMMON_CREDITOR_ID")
          .HtmlAttributes(new { style = "width:250px" })
          .Filter("contains")
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("CommonCreditors_Read", "Home");
              })
              .ServerFiltering(true);
 
          })
        )

this is my action

public ActionResult CommonCreditors_Read()
{
    GetLoggedUser("/");
    EntitiesModel entities = new EntitiesModel();
 
    var creditors = entities.TBL_COMMON_CREDITORS_LISTs
                    .Where(cc => !cc.OUT_OF_USE)
                    .OrderBy(o => o.CREDITOR_NAME)
                    .Select(cc => new { cc.CREDITOR_NAME, cc.COMMON_CREDITOR_ID });
    return Json(creditors, JsonRequestBehavior.AllowGet);
}

it isnt filtering when I type..any ideas?

16 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 10 Jun 2015, 09:13 AM

Hello Derek,

In the case of server filtering, the developer is responsible to filter the data on the backend. A string argument, containing the filter text will be received as a parameter for the action.
E.g.

public JsonResult GetProducts(string text)
{
      ...

    var products = northwind.Products.Select(product => new ProductViewModel
    {
        ...
    });
 
    if (!string.IsNullOrEmpty(text))
    {
        products = products.Where(p => p.ProductName.Contains(text));
    }
 
    return Json(products, JsonRequestBehavior.AllowGet);
}

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nithyanandam
Top achievements
Rank 1
answered on 17 Jul 2015, 12:36 PM

I am using a cascading dropdown I need server filtering implemented on this one I tried the below read action it doesn't work. 

  public JsonResult GetMenus(int subCategoryId, string text)
        {
            
            var data = Uow.Repos.GetAllMenusBySubCategory(subCategoryId);
            if (!string.IsNullOrEmpty(text))
            {
                text = text.ToLower();
                data = data.Where(p => p.Name.ToLower().Contains(text));
            }
            var collection = data.Select(x => new
            {
                ID = x.ID,
                Name = x.Name
            });
            return Json(collection, JsonRequestBehavior.AllowGet);
        }

 

Can any one help me with this. I am not finding much on searching with a combination of these two functionalities. 

 

Thanks

0
Dimiter Madjarov
Telerik team
answered on 20 Jul 2015, 08:15 AM

Hello Nithyanandam,

The provided sample code seems correct. If the problem is still perstisting, please send us small isolated runnable example that demonstrates it (here or in a support ticket), so we could inspect it locally.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nithyanandam
Top achievements
Rank 1
answered on 21 Jul 2015, 11:42 AM

Thanks for the reply Dimiter Madjarov.

 I am not sure if I have given the correct picture of the situation so I am trying again Before I send the runnable example.

 I am using this Kendo Dropdownlist In a Kendo Grid  Editor Template. 

 Below Is the Dropdown and How I am sending Cascading Value to Read

 

@(Html.Kendo().DropDownListFor(m => m.MenuId)
                               .Name("MenuId")
                               .HtmlAttributes(new { id = "MenuId", style = "width:95%;float:left;", @class = "form-control" })
                                .AutoBind(false)
                                .Filter("contains")
                         .OptionLabel("Select Menu Item...")
                         .DataTextField("Name")
                         .DataValueField("ID")
                         .DataSource(dataSource =>
                         {
                             dataSource.Read(read => read.Action("GetMenus","Set").Data("filterMenus"))
                                       .ServerFiltering(true);
                         })
                                                 .CascadeFrom("ItemSubCategoryId")
           )
 
 
function filterMenus() {
       return {
           subCategoryId: $("#ItemSubCategoryId").data("kendoDropDownList").value()
       };
   }

Here is My read 

 

public JsonResult GetMenus(int subCategoryId,string text)
       {
            
           var data = Uow.Repos.GetAllMenusBySubCategory(subCategoryId);
           if (!string.IsNullOrEmpty(text))
           {
               text = text.ToLower();
               data = data.Where(p => p.Name.ToLower().Contains(text));
           }
           var collection = data.Select(x => new
           {
               ID = x.ID,
               Name = x.Name
           });
           return Json(collection, JsonRequestBehavior.AllowGet);
       }

Is this issue caused because of the way I am sending the Data. Can I send Filter text in filterMenus javascript function is there any way I can access that over there. 

0
Dimiter Madjarov
Telerik team
answered on 21 Jul 2015, 12:05 PM

Hello Nithyanandam,

Please open a support ticket, so we could discuss the case.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Rachel
Top achievements
Rank 1
answered on 10 Sep 2015, 05:56 PM
I also have the exact same issue with cascading dropdown and server filtering. Were you able to resolve it? Can you please share the solution?
0
Dimiter Madjarov
Telerik team
answered on 11 Sep 2015, 10:08 AM

Hello Rachel,

Could you please send us an isolated runnable example that demonstrates the case, so we could have a look locally and provide assistance? I am looking forward to hearing from you.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Rachel
Top achievements
Rank 1
answered on 11 Sep 2015, 05:01 PM

I was not able to attach the whole project due to size restrictions. Please find as attachment the controller and View code which reproduces this problem. I am using

UI for ASP.NET MVC, v.2015.2.902
ASP.NET MVC 4

0
Georgi Krustev
Telerik team
answered on 16 Sep 2015, 07:12 AM
Hello Rachel,
 
I reviewed the attached code and noticed that the child widget (QueryValue) overrides the Data callback in order to send the parent's value. Thus the default one that sends the "text" parameter is removed. You can find more details here: The solution of the issue is to send the widget's filter value along with the parent's value. To get the filter value, just access the filterInput field. You can check the Data callbacks of the CascadingComboBoxes demo, as it has enabled filtering unlike the DropDownList cascading demo. 

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Rachel
Top achievements
Rank 1
answered on 16 Sep 2015, 04:35 PM
Thanks a lot for your help Georgi. I was able to solve my problem by implementing as you suggested.
0
Surinder
Top achievements
Rank 2
answered on 26 Jul 2016, 05:13 PM

Hi Dimiter,

Could you please provide back-end side code in .net asmx web service.

i mean how to process filter settings in .net web service, but not using MVC.

Regards

Surinder

0
Dimiter Madjarov
Telerik team
answered on 27 Jul 2016, 10:40 AM

Hello Surinder,

We don't have such example that we could provide at the moment.

Regards,
Dimiter Madjarov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Giovanni
Top achievements
Rank 1
answered on 26 Aug 2016, 02:46 PM

Hello Dimiter:

My filtering is still not working.

@(Html.Kendo().DropDownList()
    .Name("experimentList")
    .DataTextField("ExpName")
    .DataValueField("ExperimentID")
    .HtmlAttributes(new { style = "width:400px" })
    .Filter(FilterType.Contains)
    .Events(e => e.Change("onDDChangeExp"))
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetExperimentDropDownList", "Experiment");
        })
        .ServerFiltering(true);
    })
)

The Action:

public JsonResult GetExperimentDropDownList(string filter)
{
    ExperimentsComponent expComp = new ExperimentsComponent();
    var exps = expComp.GetOrderedQueryable();
    var list = exps.Select(e => new { e.ExperimentID, e.ExpName });
    if (!String.IsNullOrEmpty(filter))
    {
        list = list.Where(e => e.ExpName.Contains(filter));
    }
    return Json(list, JsonRequestBehavior.AllowGet); 
}

I've added the filter parameter but it is always null when the action gets called regardless of what I enter into the DDL. What am I missing?

Thank you.

 

 

0
Dimiter Madjarov
Telerik team
answered on 29 Aug 2016, 07:52 AM

Hello Giovanni,

The query string parameter of the request, containing the filter text is named text. Could you try renaming the parameter in your Action from filter to text and let me know if this fixes the issue?

Regards,
Dimiter Madjarov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Giovanni
Top achievements
Rank 1
answered on 29 Aug 2016, 06:14 PM

Yes, thank you, Dimiter. That did the job!

Now an additional question. What do I do if I need an additional parameter in my filter Action? Say in my example above, if I need to add a Category parameter, for example:

public JsonResult GetExperimentDropDownList(string text, string category)
{
    ExperimentsComponent expComp = new ExperimentsComponent();
    var exps = expComp.GetOrderedQueryable();
    var list = exps.Where(e => e.Category == category).Select(e => new { e.ExperimentID, e.ExpName });
    if (!String.IsNullOrEmpty(text))
    {
        list = list.Where(e => e.ExpName.Contains(text));
    }
    return Json(list, JsonRequestBehavior.AllowGet);
}

0
Dimiter Madjarov
Telerik team
answered on 30 Aug 2016, 07:42 AM

Hello Giovanni,

You could use the following approach for sending additional metadata to the server. It could be accessed as additional parameters in the read action.

Regards,
Dimiter Madjarov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
DropDownList
Asked by
Derek
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Nithyanandam
Top achievements
Rank 1
Rachel
Top achievements
Rank 1
Georgi Krustev
Telerik team
Surinder
Top achievements
Rank 2
Giovanni
Top achievements
Rank 1
Share this question
or