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

Shows Grid's data with optional selection in Dropdownlist

5 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Redfield
Top achievements
Rank 1
Redfield asked on 11 Jul 2017, 05:50 AM

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

5 Answers, 1 is accepted

Sort by
0
Accepted
Preslav
Telerik team
answered on 12 Jul 2017, 12:56 PM
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.
0
Redfield
Top achievements
Rank 1
answered on 13 Jul 2017, 01:34 AM

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 ?

0
Redfield
Top achievements
Rank 1
answered on 13 Jul 2017, 01:40 AM

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

}

0
Accepted
Preslav
Telerik team
answered on 14 Jul 2017, 09:42 AM
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.
0
Redfield
Top achievements
Rank 1
answered on 18 Jul 2017, 05:41 AM

Hi Preslav

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

Tags
Grid
Asked by
Redfield
Top achievements
Rank 1
Answers by
Preslav
Telerik team
Redfield
Top achievements
Rank 1
Share this question
or