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

Filtering Columns with anonymous binding

2 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 21 Jan 2015, 09:52 AM
Greetings,

I've created a grid, that displays details of an root-object. The Problem ist, that the detail-object is generated dynamically, so a direct binding to columns is not possible because we don't know what members this object has.

The "anonymous" columns in the detail-object should be filterable, but this doesn't work. Weird, because grouping is working. (The DatasourceRequest-Object in the controller seems to be correct - it has filter-definitions and group-definitions).

How can i get filtering working in my anonymous object?

This is the controller (the object "DynParts" ist the ICollection of the same dynamically created objects):
public ActionResult HierarchyBinding_Types([DataSourceRequest] DataSourceRequest request)
       {
 
           IQueryable<pxCore.Type> _types =_db.Types.OrderBy(t=>t.Kurzzeichen);
                     
           DataSourceResult _dsr = _types.ToDataSourceResult(request, _type => new Typeview(_type, _db));
                                    
           return Json(_dsr);
          
       }
 
       public ActionResult HierarchyBinding_DynParts(Guid typeid, [DataSourceRequest] DataSourceRequest request)
       {
 
           Typeview typeview= new Typeview(_db.Types.Where(w=>w.Id==typeid).FirstOrDefault(), _db);
                       
           DataSourceResult _dsr = typeview.DynParts.ToDataSourceResult(request);
 
           return Json(_dsr);
 
       }


This is the view:
@(Html.Kendo().Grid<pxCore.Type>()
        .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(e => e.Kurzzeichen).Width(110);
                columns.Bound(e => e.Bezeichnung).Width(510);
                 
            })
        .Sortable()
         
        .Scrollable()
        .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
        .ClientDetailTemplateId("template")
        .HtmlAttributes(new { style = "height:700px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
             
            .Read(read => read.Action("HierarchyBinding_Types", "Types"))
        )
        .Events(events => events.DataBound("dataBound"))
)
 
<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<object>()
            .Name("grid_#=Id#")
            .Resizable(r=>r.Columns(true))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                .Read(read => read.Action("HierarchyBinding_DynParts", "Types", new { typeID = "#=Id#" }))
                 
            )
            .Pageable()
            .Groupable()
            .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
            .Sortable()
            .Reorderable(r=>r.Columns(true))
            .ToClientTemplate()
    )
</script>


2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 23 Jan 2015, 10:12 AM
Hello Denis,

In this case the simplest solution would be to use client filtering by setting the ServerOperation option to false.

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Denis
Top achievements
Rank 1
answered on 23 Jan 2015, 10:26 AM
Hi Alexander,

thank you very much. I could not believe that it is so easy - but it works now :-)
Tags
Grid
Asked by
Denis
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Denis
Top achievements
Rank 1
Share this question
or