Angular JS UI-Grid删除行 [英] Angular JS UI-Grid Delete Row

查看:262
本文介绍了Angular JS UI-Grid删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆