Angular JS UI-Grid 删除行 [英] Angular JS UI-Grid Delete Row
问题描述
我是 ui-grid
的新手,我正在尝试在 AngularJS 中实现一个表,如下图所示.我正在尝试选择一行并使用该特定行上的删除按钮将其删除.ui-grid
文档要求我们使用 gridApi
,但我找不到足够的文档.
I'm new to ui-grid
and I'm trying to implement a table in AngularJS as shown in the picture below. I'm trying to select a row and delete it using a delete button on that particular row. The ui-grid
documentation requires us to use the gridApi
but I can't find sufficient documentation for the same.
推荐答案
请在此处查看有关如何删除行的工作示例.http://plnkr.co/edit/6TiFC6plEMJMD4U6QmyS?p=preview
Please see a working example of how to delete a row here. http://plnkr.co/edit/6TiFC6plEMJMD4U6QmyS?p=preview
关键是使用 indexOf(row.entity)
而不是依赖 row.index
,因为它不会动态更新.
The key is to use indexOf(row.entity)
and not relying on row.index
as it doesn't dynamically get updated.
$scope.deleteRow = function(row) {
var index = $scope.gridOptions.data.indexOf(row.entity);
$scope.gridOptions.data.splice(index, 1);
};
<小时>
通用方法
Generic approach
function deleteRow(row,grid) {
var i = grid.options.data.indexOf(row.entity);
grid.options.data.splice(i, 1);
}
这篇关于Angular JS UI-Grid 删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!