DropDownList server filtering - do I need additional action?

17 posts, 1 answers
  1. Derek
    Derek avatar
    104 posts
    Member since:
    Aug 2008

    Posted 09 Jun 2015 Link to this post

    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?

  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 10 Jun 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Nithyanandam
    Nithyanandam avatar
    3 posts
    Member since:
    Feb 2014

    Posted 17 Jul 2015 Link to this post

    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

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 20 Jul 2015 Link to this post

    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!
     
  6. Nithyanandam
    Nithyanandam avatar
    3 posts
    Member since:
    Feb 2014

    Posted 21 Jul 2015 Link to this post

    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. 

  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 21 Jul 2015 Link to this post

    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!
     
  8. Rachel
    Rachel avatar
    8 posts
    Member since:
    Feb 2013

    Posted 10 Sep 2015 in reply to Nithyanandam Link to this post

    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?
  9. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 11 Sep 2015 Link to this post

    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!
     
  10. Rachel
    Rachel avatar
    8 posts
    Member since:
    Feb 2013

    Posted 11 Sep 2015 in reply to Dimiter Madjarov Link to this post

    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

  11. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 16 Sep 2015 Link to this post

    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!
     
  12. Rachel
    Rachel avatar
    8 posts
    Member since:
    Feb 2013

    Posted 16 Sep 2015 in reply to Georgi Krustev Link to this post

    Thanks a lot for your help Georgi. I was able to solve my problem by implementing as you suggested.
  13. Surinder
    Surinder avatar
    1 posts
    Member since:
    Apr 2015

    Posted 26 Jul in reply to Dimiter Madjarov Link to this post

    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

  14. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 27 Jul Link to this post

    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.
     
  15. Giovanni
    Giovanni avatar
    3 posts
    Member since:
    Feb 2016

    Posted 26 Aug in reply to Dimiter Madjarov Link to this post

    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.

     

     

  16. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 29 Aug Link to this post

    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.
     
  17. Giovanni
    Giovanni avatar
    3 posts
    Member since:
    Feb 2016

    Posted 29 Aug in reply to Dimiter Madjarov Link to this post

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

  18. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 30 Aug Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready