user3403666
user3403666

Reputation: 61

Delete remove functionality for last row in ng-grid?

I have functionality that allows my ng-grid to remove rows in which when you click the remove button, the row is deleted from the ng-grid. Below is an example of how I have it set up now:

http://plnkr.co/edit/NL7sMGT6acdUHAAZPNba?p=preview

I want to get it so that the remove button disappears on the very last row. In the example above, for example, all but the Enos entry would have no delete button. Also, if I created a new row under Enos, I would have it so that Enos would then have a remove button and the new row under Enos would have no delete functionality. I have the functionality to add/remove rows, but I simply want to get the remove button to disappear on the last row. How would I do so?

Any help would be appreciated. Thanks!

Upvotes: 0

Views: 299

Answers (1)

Steve Greatrex
Steve Greatrex

Reputation: 15999

You can use the ng-hide directive to hide the button when the row index is the last one in the collection:

<input type="button" 
  value="remove" 
  ng-click="removeRow()" 
  ng-hide="row.rowIndex == $parent.myData.length-1" />

This uses the $parent property to access the original list on the parent scope to get the count.

Upvotes: 2

Related Questions