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

Nested grids with common data source

2 Answers 518 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 01 Feb 2012, 01:11 AM
I am implementing a solution that uses nested grids to drill-down on an organization hierarchy. The entire organization is obtained from a single data source. I have found that the dataSource binding does not initialize when showing the detailTemplate.

I created the following minimal example to demonstrate the issue.

<div id="grid"></div>
 
<script>
    $(document).ready(function () {
        var dataSource = new kendo.data.DataSource({
            type: "odata",
            transport: {
                read: "http://demos.kendoui.com/service/Northwind.svc/Employees"
            }
        });
 
        var element = $("#grid").kendoGrid({
            dataSource: dataSource,
            columns: ["FirstName", "LastName"],
            height: 450,
            detailInit: detailInit,
            dataBound: function () {
                this.expandRow(this.tbody.find("tr.k-master-row").first());
            }
        });
    });
 
    function detailInit(e) {
        $("<div/>").appendTo(e.detailCell).kendoGrid({
            dataSource: dataSource,
            /*dataSource: {
                type: "odata",
                transport: {
                    read: "http://demos.kendoui.com/service/Northwind.svc/Employees"
                }
            },*/
            columns: ["FirstName", "LastName"],
            scrollable: false
        });
    }
</script>

This results in an error: dataSource is not defined.

If you comment out the dataSource property within detailInit and uncomment the one immediately afterwards, then it works.

In case it is relevant, this markup is being loaded via AJAX and inserted into the DOM via jQuery. 

My business need is to bind the main grid and the sub-grids to the same data source. It's not shown in the basic example, but this will be iterative to dozens of levels, so I really need to be able to use a single data source.

Thanks,
Gary

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 01 Feb 2012, 09:49 AM
Hello Gary,

The error you have described is caused by the fact that the dataSource variable is declared in the scope of the document ready handler, thus it is not available outside of this function scope. You should declare the variable in more global scope in order to be accessible form other functions.

Regarding the single DataSource hierarchy. I'm afraid that this is not supported, as you may know when data source is filtered all of the attached widgets will be rebound to reflect the changes. This will result in that all of the widgets in the hierarchy will show same data. 

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gary
Top achievements
Rank 1
answered on 01 Feb 2012, 04:37 PM
Thank you for explaining this. I did not know that the behavior of the data source is as you described, but it makes sense.
Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Gary
Top achievements
Rank 1
Share this question
or