无法获得父网格的正确行数

时间:2013-08-08 10:47:06

标签: javascript jquery asp.net-mvc-4 kendo-grid

我无法获取子网格数据,如获取父网格数据和从父网格获取错误的行数...我使用的是kendo ui网格层次结构网格格式,我正在使用下面的代码用于此目的

<script type="text/javascript">
$(document).ready(function () {
    $('#btnMove').click(function () {

        var count = $('#Gridparent').data('kendoGrid').tbody[0].rows.length;

        alert(count); // here I am getting 5 number but actually i hav 4 rows 

        var sourcegrid = $('#GridParent').data('kendoGrid');  
        alert(' first button clicked');  // here is  ok    

        var destinationgrid = $('#grid_#=CostPage#').data('kendoGrid');
        alert('second button clicked'); // not getting this alert

这是我的观点

@using (Html.BeginForm())
{ 
   @(Html.Kendo().Grid<Topco.TopMapp.MVC.Models.CostPageSearch>()
        .Name("Gridparent")
        .Columns(columns =>
        {
            columns.Template(@<text></text>).ClientTemplate("<input id='checkbox' onclick='grdChkBoxClick(this); ' class='chkbxq' type='checkbox' />").Width(30);
            columns.Bound(e => e.CostPage).Width(100);
            columns.Bound(e => e.Description).Width(100);
            columns.Bound(e => e.VendorName).Width(100);
            columns.Bound(e => e.BillTypeDirect).Width(100);
            columns.Bound(e => e.BillTypeWarehouse).Width(100);
            columns.Bound(e => e.VendorName).Width(100);    
        })
        .ClientDetailTemplateId("client-template")
        .HtmlAttributes(new { style = "height:480px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(6)
            .Read(read => read.Action("HierarchyBinding_Employees", "CostPageDisplay"))
        )
        .Events(events => events.DataBound("dataBound"))
)
    <script id="client-template" type="text/kendo-tmpl">
         @(Html.Kendo().Grid<Topco.TopMapp.MVC.Models.ItemsDescriptionModel>()
            .Name("grid_#=CostPage#")
            .Columns(columns =>
            {
                columns.Template(@<text></text>).ClientTemplate("<input id='checkbox' onclick='grdChkBoxClick(this); ' class='chkbxq' type='checkbox' />").Width(30);
                columns.Bound(o => o.ItemId).Width(100);
                columns.Bound(o => o.ItemDescription).Width(100);
                columns.Bound(o => o.BrandCode).Width(100);
                columns.Bound(o => o.PackSize).Width(100);
            })
           .DataSource(dataSource => dataSource
               .Ajax()
               .PageSize(5)
               .Read(read => read.Action("HierarchyBinding_Orders", "CostPageDisplay" , new { employeeID = "#=CostPage#" }))
           )
           .ToClientTemplate()
   )
    </script>
<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
        //alert('1');
    }
</script>

我无法看到警告second button clicked,也无法获得正确的行数以及以下代码

            var count = $('#Gridparent').data('kendoGrid').tbody[0].rows.length;
任何人都会对此有所帮助..非常感谢....

1 个答案:

答案 0 :(得分:0)

我已用这些行解决了问题....我从第一行获取数据并且我从第二行得到正确的行数...

var childGriddata = $('#GridParent').closest(".k-grid").data("kendoGrid"); 

var actualrowcount = $('#Gridparent').data("kendoGrid").dataSource.total();