I have a master detail grid in kendo Grid and I am using the angular version of the Kendo Grid.
I have added a custom button for adding a new record in each row of the grid and the records is added below the row on which the button is clicked.
Below is the code that is working.
Button Template
<img src='images/save.png' ng-click='onClick()'
class='k-grid-add' title='Add new record' alt='Create'/>
The click function
$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, {});
}
This part is working fine. Now the problem is that I need similar button in each row in the child grid too. But I don't know how to get the dataSource of the child grid in angular. I believe if I can get the child grid then the above code could be used to add a new row using the index.
Thanks for your time, Feel free to ask if any other information is required.
Thanks
答案 0 :(得分:0)
不确定这是否是最好的方法,但我通过点击子网格行中的添加按钮使用以下函数来实现它。
$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)'