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

Grid doesn't filter results

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Larry asked on 25 Mar 2018, 09:40 PM

HI,

 

The filtering options show for each column, but when "Filter" is clicked nothing changes in the grid.

 

@(Html.Kendo().Grid<FlRazor2.Models.Header>()
                                .Name("grid")
                                .Columns(columns =>
                                {
                                    columns.Bound(p => p.id).Title("Case ID");
                                    columns.Bound(p => p.individual.firstName).ClientTemplate("#=individual? individual.firstName:''#").Title("First Name");
                                    columns.Bound(p => p.individual.lastName).ClientTemplate("#=individual? individual.lastName:''#").Title("Last Name");
                                            //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
                                        })
                                .ToolBar(tools =>
                                {
                                            //tools.Create();
                                        })
                                .Sortable()
                                .Pageable()
                                //.Filterable()
                                .Filterable(filterable => filterable
                                    .Extra(false)
                                        .Operators(operators => operators
                                        .ForString(str => str.Clear()
                                        .Contains("Contains")
                                        .IsEqualTo("Exactly matches")
                                        .StartsWith("Starts with"))))
                                .DataSource(dataSource =>
                                dataSource
                                .WebApi()
                                .Model(model =>
                                {
                                    model.Id(p => p.id);
                                })
                                .Events(events => events.Error("error_handler"))
                                .Read(read => read.Action("Get", "Home"))
                                //.Create(create => create.Action("Post", "Product"))
                                //.Update(update => update.Action("Put", "Product", new { id = "{0}" }))
                                //.Destroy(destroy => destroy.Action("DELETE", "Product", new { id = "{0}" }))
                                )
                    )

 

from controller:

[HttpGet]
        public DataSourceResult Get([DataSourceRequest]DataSourceRequest request, string t)
        {
            string userName = User.Identity.Name;
            int indexOfSlash = userName.IndexOf("\\");
            userName = userName.Substring(indexOfSlash + 1).ToLower();

            //DataSourceResult test = service.Read().ToDataSourceResult(request);
            //return service.Read().ToDataSourceResult(request);
            IEnumerable<Header> headers = _service.Read();
            DataSourceResult result = new DataSourceResult();
            result.Data = headers;
            result.Total = headers.Count();
            return result;
        }

 

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 28 Mar 2018, 10:33 AM
Hello Larry,

I have examined the code and it seems like the Read action of the DataSource always returns all items. In order to return the filtered results please ensure that filtering is applied before returning the data to the client. Please check out the example below that illustrates the approach:


Give the modification a try and let me know how it works for you.

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Larry
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or