Grid Column Filter/Sort With Client Template

1 Answer 68 Views
Filter Grid
Mike
Top achievements
Rank 1
Iron
Mike asked on 24 May 2023, 11:12 PM

I have a grid defined as thus:

@(Html.Kendo().Grid<SubServiceViewModel>()
    .Name("SubServiceGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Hidden(true);
        columns.Bound(c => c.Service)
            .ClientTemplate("#=Service.Value#")
            .Filterable(false)
            .Sortable(false);
        columns.Bound(c => c.Value);
        columns.Bound(c => c.Active).Hidden(true);
        columns.Bound(c => c.Deleted).Hidden(true);
        columns.Command(c => c.Destroy());
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable(pager => pager.Refresh(true))
    .Sortable()
    .Filterable()
    .NoRecords()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .PageSize(10)
        .ServerOperation(true)
        .Events(events => events.Error("error_handler").RequestEnd("onRequestEnd('staticNotifications')"))
        .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.Service).DefaultValue(ViewData["defaultService"] as ServiceViewModel);
            model.Field(p => p.Value);
            model.Field(p => p.Active).DefaultValue(EntityLiterals.Yes);
            model.Field(p => p.Deleted).DefaultValue(EntityLiterals.No);
        })
        .Read(read => read.Action("GetSubServices", "SubService").Data("forgeryToken"))
        .Create(create => create.Action("CreateSubServices", "SubService").Data("forgeryToken"))
        .Update(update => update.Action("UpdateSubServices", "SubService").Data("forgeryToken"))
        .Destroy(destroy => destroy.Action("DeleteSubServices", "SubService").Data("forgeryToken"))
    ))

And if I remove the 

.Filterable(true)

I get a JS error when I click the column filter button


Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at C (kendo.all.js:318535:21)
    at init._createForm (kendo.all.js:318535:21)
    at init._init (kendo.all.js:318535:21)
    at init._click (kendo.all.js:318535:21)
    at HTMLAnchorElement.dispatch (jquery.min.js?v=oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl-cbzUq8:2:43184)
    at y.handle (jquery.min.js?v=oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl-cbzUq8:2:41168)
C @ kendo.all.js:318535
_createForm @ kendo.all.js:318535
_init @ kendo.all.js:318535
_click @ kendo.all.js:318535
dispatch @ jquery.min.js?v=oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl-cbzUq8:2
y.handle @ jquery.min.js?v=oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl-cbzUq8:2
However, because I'm using InCell editing, I have a ViewData object populated with my DropDown items (with the UI Hint), similar to the demo.  Is there any way around this?

1 Answer, 1 is accepted

Sort by
0
Accepted
Mike
Top achievements
Rank 1
Iron
answered on 25 May 2023, 04:16 AM
I actually solved this issue by following this link.
Tags
Filter Grid
Asked by
Mike
Top achievements
Rank 1
Iron
Answers by
Mike
Top achievements
Rank 1
Iron
Share this question
or