0

I have a MVC Kendo grid where one column is a client template that actually uses multiple fields. By default the built in filtering is only applied to the field the column is bound to. How do I override that so it considers both fields. Ie, when I search for "Contains" "De" a column that displays "Detroit, MI" should return.

Here's what I have so far:

MVC View

        @(Html.Kendo().Grid<ViewModel>()
        .DataSource(dataSource => dataSource
            .Custom()
            .Transport(t =>
            {
                t.Read(r => r.Action("StatusGridRead", "DeviceStatus"));
            })
            .Schema(schema => schema
                .Data("Result.Data")
                .Total("Result.Total")
                .Errors("Result.Errors")
            .Model(m =>
            {
                m.Id(f => f.Id);
                m.Field(f => f.StateOrProvince);
                m.Field(f => f.City);
                ...
            })
            )
        )
        .Columns(columns =>
        {
            columns.Bound(c => c.StateOrProvince).Title("City & State").ClientTemplate("#=City#, #=StateOrProvince#");
            ...
        })
        .Events(e=>
        {
            e.Filter("statusGridFilter");
        })
        .Sortable()
        .Filterable(f =>
        {
            f.Extra(false);
            f.Operators(o => o.ForString(s =>
            {
                s.Clear();
                s.Contains("Contains");
                s.IsEqualTo("Is Equal To");
                s.StartsWith("Starts With");
                s.EndsWith("Ends With");
                s.DoesNotContain("Does Not Contain");
                s.IsNotEqualTo("Is Not Equal To");
            }));
        })
        ) 

Javascript

function statusGridFilter(e) {
    if (e.field == "StateOrProvince") {
        //What do I do here? 
    }
}

I understand if I made a column for city and one for state that would resolve this issue, however I actually have a similar scenario (client template with many string fields displayed) where that won't work and am just picking this as the easiest example. Other than making 1 column for 1 field, I'm open to any other ideas that may solve filtering for this scenario.

Natalka
  • 258
  • 1
  • 14
  • This may answer your question: https://stackoverflow.com/questions/41987788/kendo-ui-grid-filtering-column-with-multiple-values – MentallyRecursive Dec 26 '19 at 21:56
  • That helps immensely and I do have a working solution, although it feels like there probably a better way. Basically on the filter event I captured and determined the filtering logic, then once the grid has finished doing it's thing I applied the filters manually to the datasource in the grid's onDataBound event. – Natalka Dec 30 '19 at 21:22
  • Yeah I think that's the only way to get it done right now. The only other way I could think of is to add the other column(s) as hidden and apply the filter to both, which is almost the same thing, and which you have stated you don't want to do. – MentallyRecursive Dec 30 '19 at 21:32

0 Answers0