javascript - 使用 Angular 获取 Kendo 中子网格的数据源

标签 javascript angularjs kendo-grid

我在 kendo Grid 中有一个主细节网格,并且我正在使用 Kendo Grid 的 Angular 版本。

我添加了一个自定义按钮,用于在网格的每一行中添加新记录,并且记录将添加到单击该按钮的行下方。

下面是正在运行的代码。

按钮模板

<img src='images/save.png' ng-click='onClick()'
 class='k-grid-add' title='Add new record' alt='Create'/>

点击函数

$scope.onClick = function ()
{               
    var grid = $scope.grid;    
    var sel = grid.select();    
    var item = grid.dataItem(sel);    
    var index = grid.dataSource.indexOf(item);
    grid.dataSource.insert(index + 1, {});
}

这部分工作正常。现在的问题是我在子网格的每一行中也需要类似的按钮。但我不知道如何以 Angular 获取子网格的数据源。我相信如果我可以获得子网格,那么上面的代码可以用于使用索引添加新行。

感谢您的宝贵时间,如果需要任何其他信息,请随时询问。

谢谢

最佳答案

不确定这是否是最好的方法,但我通过在单击子网格行中的添加按钮时使用以下函数来使其工作。

$scope.commomAddClick = function ($event) {
    var childGrid = $($event.currentTarget).closest(".k-grid").data("kendoGrid");
    var sel = childGrid.select();
    var item = childGrid.dataItem(sel);
    var index = childGrid.dataSource.indexOf(item);
    childGrid.dataSource.insert(index + 1, {});
};

在添加按钮中,我将点击事件连接为

ng-click='commomAddClick($event)'

关于javascript - 使用 Angular 获取 Kendo 中子网格的数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31610948/

相关文章:

kendo-grid - 如何在 Kendo Grid 中隐藏列组

javascript - 检查是否输入了文本。找不到错误

javascript - 在 Javascript 中从 URL 获取 JSON 数据

javascript - 使用 Angular.js 和 PHP 时过滤器功能无法按预期工作

c# - 剑道下拉返回对象对象

javascript - 添加数据后,分页在 Kendo UI 网格中不起作用

javascript - 在 Foundation 6 中创建在滚动条上显示当前位置的导航

javascript - 使用 .replaceWith 更改 dom

javascript - 在 body 标签上使用 ng-view 有什么缺点吗?

javascript - 在ui-select中获取所选选项的索引 - Angularjs