25

I am using angular button in a ng-grid. I need to know how can i identity which button was clicked from within the grid.

I guess part of the complexity is that the button is clicked before the row is selected (Just my analysis,probably wont help with the solution :)

A snap shot of how the grid looks

ng-grid

A plunker illustrating the problem here

2 Answers 2

26

I have been able to find out how to resolve my question,basically pass in "row" as an argument on your function for ng-click. ng-click="save(row)"

Before

.. ng-click="edit(selectedItem)" >Edit</button> '

After

.. ng-click="edit(row)" >Edit</button> '

I have updated the plunker here to reflect the same

row.entity will give me the entity bound to this row of the grid

Sign up to request clarification or add additional context in comments.

4 Comments

Perfect, thank you! Where did you find info on the entity object?
I am sorry, i have kind of lost touch with AngularJS, however i do remember looking it up on some blog and then having the same unanswered query, it would be great it someone could add to the answer
@Sudarshan Do you know how to prevent the row from being selected when you press the "edit" button?
I found .entity in the js debugger. Yes, I'm taking a dependency on an undocumented property and am well aware of the risk.
5

@Shai Aharoni You can prevent the row from being selected by passing $event as the first argument to the click handler:

.. ng-click="edit($event, row)">Edit</button>

and then calling stopPropagation() on the event from inside the handler.

$scope.edit = function(event, row) { event.stopPropagation(); }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.