我在 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/