Filtering Columns with anonymous binding

3 posts, 1 answers
  1. Denis
    Denis avatar
    2 posts
    Member since:
    Jan 2015

    Posted 21 Jan 2015 Link to this post

    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. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 23 Jan 2015 Link to this post

    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.

     
  3. Denis
    Denis avatar
    2 posts
    Member since:
    Jan 2015

    Posted 23 Jan 2015 in reply to Alexander Popov Link to this post

    Hi Alexander,

    thank you very much. I could not believe that it is so easy - but it works now :-)
Back to Top