John H
John H

Reputation: 14655

Why is this initial Kendo grid filter not working?

I have a model like so:

Id    Type
-------------
1     Vehicle
2     Trailer
3     Vehicle

I am hoping to eventually use a radio button to control how this data is filtered on a Kendo grid, choosing to filter on whether Type equals Vehicle or Trailer. I don't know how to do that, but, for now, I can't even get the initial filter to work. My grid is as follows:

@(Html.Kendo().Grid<PcKendoUi.Models.CompanyDueDatesIndexVM>()
    .Name("DueDates")
    .Columns(columns =>
    {
        columns.Bound(c => c.Id);
        columns.Bound(c => c.Type);
    })
    .Filterable()
    .DataSource(ds => ds
        .Ajax()
        .Model(m => m.Id(x => x.Id))
        .Read(s => s.Action("Test", "CompanyDueDates"))
        .Filter(filter =>
        {
            filter.Add(f => f.Type == "Vehicle");
        })
     )
)

My code is based on the filter example from the documentation.

This still displays all 3 records in the model, rather than just rows 1 and 3. What is also interesting is that after specifying this initial filter, the filter controls also do not allow any filter. That is, they are visible, I can type in data and click Filter, but it will not filter the grid.

Does anyone have an idea what the problem could be?

Upvotes: 0

Views: 932

Answers (1)

OnaBai
OnaBai

Reputation: 40887

According the documentation your syntax is not correct, you wrote:

filter.Add(f => f.Type == "Vehicle");

When it should be:

filter.Add(f => f.Type).IsEqualTo("Vehicle");

Upvotes: 1

Related Questions