【问题标题】:How to filter data for a nested Kendo UI datasource in Hierarchy grid如何在层次网格中过滤嵌套 Kendo UI 数据源的数据
【发布时间】:2015-05-29 21:03:57
【问题描述】:

如何过滤层次网格中嵌套 Kendo UI 数据源的数据 以下是数据源:

Obj1{"Name":"abc","id":1 ,Obj2 {{"Name":"A1","oid":1},{"Name":"A2","oid":2}}

我需要搜索出现在详细网格中的 Obj2 名称。 请帮忙。

【问题讨论】:

    标签: javascript jquery kendo-ui


    【解决方案1】:

    使用您的数据准备 viewModel 和数据源

    $(document).ready(function () {
    var viewModel = kendo.observable({
        //here define a datasource - i followed your data with improv
        datasource: new kendo.data.DataSource({
            data: [{
                name: 'abc',
                id: 1,
                obj2: [{
                    name: 'a1',
                    oid: 1
                }, {
                    name: 'b1',
                    oid: 2
                }, {
                    name: 'c1',
                    oid: 3
                }]
            }, {
                name: 'def',
                id: 4,
                obj2: [{
                    name: 'd1',
                    oid: 4
                }, {
                    name: 'e1',
                    oid: 5
                }]
            }, {
                name: 'ghi',
                id: 3,
                obj2: [{
                    name: 'g1',
                    oid: 6
                }, {
                    name: 'h1',
                    oid: 7
                }]
            }]
        }),
        //define the function when we want to click the expand button
        detail: function (e) {
            //bind it now
            kendo.bind(e.detailCell, e.data);
        }
    });
    
    //1 st bind container with the kendo observable
    kendo.bind('#container', viewModel);
    
    //grab the grid and bind its 'detailInit' event with our 'detail' function
    var grid = $('#grid').getKendoGrid();
    grid.bind('detailInit', viewModel.detail);
    

    });

    并准备 html 网格和详细网格的模板

    <div id="container">
        <br/>
        <br/>
        <div id="grid" data-role="grid" data-bind="source: datasource" data-detail-template="child-template" data-columns="[
                { field: 'name' },
                { field: 'id' },
            ]"></div>
    </div>
    <script id="child-template" type="text/x-kendo-template">
        <div data-role = "grid"
        data-bind = "source: obj2"
        data-columns = "[
        { field: 'name' },
        { field: 'oid' }
        ]"> </div>
    </script>
    

    最后这是jsfiddle,这个tutorial教我怎么做

    编辑:我在每个详细信息网格顶部添加了一个下拉列表,因此您可以从那里过滤它们,这是jsfiddle

    【讨论】:

    • @Machun ....我可以使用层次结构网格在该显示中获取它,但问题是我想放置一个过滤器文本框,并且当我在每个按键上过滤数据源时它无法识别嵌套对象的值。就像我想过滤名称“A1”一样。
    • @Piyush 我会更新我的答案和 jsfiddle,稍后看看
    • @Manchun ..... 谢谢,但我需要的过滤器文本框是过滤所有详细的网格。意味着如果我过滤“d”,那么所有详细的网格都会出现,主网格行的名称从“d”开始。我们可以在常规数据源上使用过滤器,例如 grid.dataSource.filter({ field: "Name", operator: "contains", value: filterseriesTextName });
    • @Piyush,你找到解决方案了吗?我有完全相同的要求。感谢分享。
    【解决方案2】:

    我遇到了同样的问题,无法在子网格中应用过滤器。

    解决方法如下:

    我的html代码:

                <div class="panel-body custom-table" id="divAllCall">
                    <div class="row">
                        <div class="col-md-12">
                            @(Html.Kendo().Grid<FW.Model.model>()
                            .Name("gridTest")
            .Columns(col =>
            {
                col.Bound(c => c.Id).Hidden(true);
                col.Bound(c => c.Name).Title("Name").HeaderHtmlAttributes(new { title = "Port" }).Width(100);
                col.Bound(c => c.col1).Title("col1").HeaderHtmlAttributes(new { title = "Upcoming Calls" }).Width(100);
                col.Bound(c => c.col2).Title("col2").HeaderHtmlAttributes(new { title = "Calls In Port" }).Width(100);
    
    
            })
            .Sortable()
            .Scrollable()
            .HtmlAttributes(new { style = "height: 380px" })
            .Pageable(pageable => pageable.Refresh(true)
            .PageSizes(new int[5] { 20, 40, 80, 100, 200 })
            .ButtonCount(5))
                            .ClientDetailTemplateId("TestTemplate")
            .DataSource(dataSource => dataSource
                .Ajax()
    
                .PageSize(10)
                        .Read(read => read.Action("TestAction", "TestController"))
            )
                            )
                            <script id="TestTemplate" type="text/kendo-tmpl">
                                @(Html.Kendo().Grid<FW.Model.model1>()
                    .Name("ChildGrid#=Id#") // template expression, to be evaluated in the master context
    .Columns(col =>
    {
        col.Bound(o => o.Id).Hidden(true);
    
        col.Bound(o => o.name).Width(100).ClientTemplate("\\#= BuildLink(data,'1') \\#");
        col.Bound(o => o.testName).Width(100).ClientTemplate("\\#= BuildLink(data,'2') \\#");
        col.Bound(o => o.TestName1).Width(100).ClientTemplate("\\#= BuildLink(data,'3') \\#");       
    })
    .Filterable(x=>x.Mode(GridFilterMode.Row))
                            .Scrollable()
                    .DataSource(dataSource => dataSource
                    .Ajax()
                                    .Read(read => read.Action("TestAction2", "TestController2", new { Id= "#=Id#", maxCalls = "#=MaxCalls#" }))
                        ).Events(events => events.DataBound("DataBound_AllCallChild"))
    
                .ToClientTemplate()
                                )
                            </script>
                        </div>
                    </div>
                </div>
            </div>
    
        </div>
    </div>
    

    在这里查看.Filterable(x=&gt;x.Mode(GridFilterMode.Row)) 我是如何应用过滤器的,我在这里使用了重载函数并使用了 GridFilterMode.Row 而不是 GridFilterModel.menu。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      相关资源
      最近更新 更多