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

Filter Grid By ComboBox (Razor)

0 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 14 Nov 2012, 08:53 PM
Hey guys,

I'm relatively new to Kendo UI and just had a question about filtering a grid by using values from a combobox. From my understanding I can do something like this:

@(Html.Kendo().ComboBox()
                .Name("combobox name")
                .Events(e=>e.Change(@<text>
                                     function(e) {
                                        var grid = $("#Grid").data("kendoGrid");
                                        var value = this.value();
                                        if(value) {
                                                grid.dataSource.filter({ field: "filter field", operator: "eq", value: parseInt(value) });
                                               }
                                        else{
                                                grid.dataSource.filter({});
                                            }
                                        }
                                     </text>
                    )
                  )
                .Placeholder("Place holder..")
                .DataTextField("Text")
                .DataValueField("Value")
                .DataSource(source => {
                    source.Read(read => 
                    {
                        read.Action("Controller Action", "Controller");
                    });
                })
                .SelectedIndex(0)

I've tried this and leads it filters my grid with my desired results, but if I go about it this way and try to add a new item, the item is then added to the unfiltered page of the grid (which is not desirable). From a few other posts I have read, I found I could navigate around this issue simply by adding a few things to to the filter command, like so:

   grid.dataSource.filter({logic: "or", filters[{ field: "filter field", operator: "eq", value: parseInt(value) }, { field: "filter field", operator: "eq", value: 0 }]})

Having that allows me to, when I click add a new item, to have that item show up on the filtered page of the grid. However, I am then unable to save that newly created instance. I wonder is there another way of filtering a grid using a combobox? If there is, any help/ advice would be really helpful.

                           Thanks,
                                          Chris

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Share this question
or