如何在特定索引处的 ui-grid 中添加新行
How to add new row in ui-grid at specific index
我需要在 ui- 网格内的特定索引处添加一个新行。
所以我想出了如何在网格内添加新行,但问题是我需要在所选行之后而不是在网格顶部添加新行。
基本上我不知道如何获取clicked/selected行的索引
$scope.addNew = function() {
$scope.gridOptions.data.unshift({});
};
这是 plunker 我目前所做的
我没有在代码中看到任何可以帮助你的东西,但你可以使用简单的 js 方法来完成。
您现在只需要获取所选行的实体(例如,如果您使用的是 celNav
的 gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol){})
,您可以从 newRowCol.row.entity
中获取),然后您可以通过调用找到它在 gridOptions.data
中的索引:
gridOptions.data.indexOf(rowEntity)
你可以在你的 plunkr 的 new version 中看到我是怎么做的。
我需要在 ui- 网格内的特定索引处添加一个新行。 所以我想出了如何在网格内添加新行,但问题是我需要在所选行之后而不是在网格顶部添加新行。
基本上我不知道如何获取clicked/selected行的索引
$scope.addNew = function() {
$scope.gridOptions.data.unshift({});
};
这是 plunker 我目前所做的
我没有在代码中看到任何可以帮助你的东西,但你可以使用简单的 js 方法来完成。
您现在只需要获取所选行的实体(例如,如果您使用的是 celNav
的 gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol){})
,您可以从 newRowCol.row.entity
中获取),然后您可以通过调用找到它在 gridOptions.data
中的索引:
gridOptions.data.indexOf(rowEntity)
你可以在你的 plunkr 的 new version 中看到我是怎么做的。