Shows Grid's data with optional selection in Dropdownlist

6 posts, 2 answers
  1. Redfield
    Redfield avatar
    10 posts
    Member since:
    Jun 2017

    Posted 11 Jul 2017 Link to this post

    i'm writing a website using kendo grid, and now i'm stuck in displaying the Selective Data when i chose an item on the drop down list, i don't use the Filter action but instead i'm using a Ajax which will call my Jsonresult in the controller. How to make the grid show those items ? 
    Here is the method in my Controller :

    public JsonResult LoadSelection(Categories Option)
            {
                try
                {
                    List<Product> ls = new List<Product> { };
                    foreach (var item in db.Product.ToList())
                    {
                        if (item.Cate_ID== Option.Cate_ID)
                            ls.Add(item);                
                    }
                    return new JsonResult()
                    {
                        Data = ls,
                        MaxJsonLength = Int32.MaxValue,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    
                }
                catch (Exception e)
                {
                    return Json(e.Message);
                }

    and here is my dropdownlist handler :
     var dropdown = grid.find("#Item").kendoDropDownList({
                   dataTextField: "Cate_ID",
                   dataValueField: "Cate_ID",
                   autoBind: false,
                   optionLabel: "All",
                   dataSource: Shared_Data,           
                   change: function () {
                       var value = this.value();
                       if (value) {
                           Selected_Data = value;
                               $.ajax({
                                   data: {"ID_LoaiKH":Selected_Data },
                                   url: "/Product/LoadSelection",
                                   type: "GET",
                                   dataType: "json",
                                   success: function()
                                   {
                                       $("#grid_1").data('kendoGrid').dataSource.read();
                                   }
                               });

  2. Answer
    Preslav
    Admin
    Preslav avatar
    583 posts

    Posted 12 Jul 2017 Link to this post

    Hi Redfield,

    Based on the provided information, I assume that your project has a DropDownList outside the Grid. Based on that DropDown controller, the grid should be filtered. 

    If this is the case, please refer to this forum post: http://www.telerik.com/forums/filter-grid-based-on-controls-outside-of-grid

    Regards,
    Preslav
    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. Redfield
    Redfield avatar
    10 posts
    Member since:
    Jun 2017

    Posted 12 Jul 2017 Link to this post

    Hi Preslav, 

    Thanks for the reply, i think i've solved that problem, i just want to ask that how can i retrieve more than one value from view to controller in the Ajax Data . Like the Above Example , i want to get two values like this :

     data: {"Field": some_var , "ID_Cate" : Selected_Data },

    Is this the right code ?

  4. Redfield
    Redfield avatar
    10 posts
    Member since:
    Jun 2017

    Posted 12 Jul 2017 Link to this post

    More info :
    The controller should be something like this :

    public JsonResult SomeJsonAction( ClassA  Field_ID , ClassB Cate )

    {

    //some action

    }

    in which

    public classA 

    {

    public string Field { get ; set; }

    }

    and

     public Class B 

    {

     public int Cat_ID {get ;set; }

     public String Cate_Name { get; set;}

    }

  5. Answer
    Preslav
    Admin
    Preslav avatar
    583 posts

    Posted 14 Jul 2017 Link to this post

    Hi Redfield,

    I would suggest using JSON.stringify on the data.

    Additionally, I believe that you might be interested in checking these forum posts:
    Regards,
    Preslav
    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.
  6. Redfield
    Redfield avatar
    10 posts
    Member since:
    Jun 2017

    Posted 18 Jul 2017 in reply to Preslav Link to this post

    Hi Preslav

    Thanks for the Reply, It's ok now, thank you very much

Back to Top