trNgGrid icon indicating copy to clipboard operation
trNgGrid copied to clipboard

Define ng-click on rows

Open greghaar opened this issue 12 years ago • 2 comments

Have been looking for a decent grid for a while now and wasn't happy at all with ng-grid, ng-table, wijmo or kendo... this looks SUPER promising.

I'm trying to convert an ng-table directive that contained an ng-click="open(myItems.id)" directive on which would call the open method in the controller (and handle opening a new route with the details for that record). It's not entirely clear if that's possible or how I would do that in trNgGrid, both defining a custom click method in place of selections or referencing that row's id value.

Any ideas, or is this possible as an enhancement?

Thanks for the great work to date, it seems like you've made some serious progress in the last few months!

greghaar avatar Jul 16 '14 04:07 greghaar

I do something similar, but instead of routing to a new page, I just display the details below. I'll post what I use below. This is probably not the best way to do it, but it should work.

<table items="offices" tr-ng-grid="" selected-items="officeDetails" 
           selection-mode="SingleRow"></table>
$scope.$watch('officeDetails[0]', function (value) {
     $scope.offDetail = _.find($scope.offices, function (office) {
          return office.officeId === value.officeId
     })
});

rphilp avatar Jul 16 '14 13:07 rphilp

Yep, that is the way to go:

  1. Monitor the collection you attach to selected-items.
  2. Alternatively, if you don't need more data, you could directly couple the first item in the selection collection directly to a div having a ng-if or ng-show directive.

The grid uses dual data binding for most of its features which makes it convenient to attach extra logic, the Angular way.

MoonStorm avatar Jul 17 '14 15:07 MoonStorm