Tim
Tim

Reputation: 7431

how can i bind to the current selected row in ng-grid?

My ng-grid is set to multiSelect: false, and I want to show or potentially query externally for some additional data whenever a row is clicked. The scenario is for example showing the body of an email when one is selected from a grid listing emails.

<div ng-app="app" ng-controller="emailController">
    <div class="gridStyle row-fluid" ng-grid="gridOptions">
        <input  placeholder="enter to filter title" ng-model="filterText" ng-change="filterTxt(this)"/>
        <label>Include Sent: <input type="checkbox" title="IncludeCompleted" ng-model="_IncCompleted" ng-click="IncludeCompleted()"></label>
    </div>

    <div class="row-fluid gridStyle">
        <p></p>
        <br />
        <br />
        <input type="text" ng-model="messageBody" />
    </div>

</div>

Upvotes: 1

Views: 2850

Answers (1)

Gilad Peleg
Gilad Peleg

Reputation: 2010

Bind it to a $scope var using this:

$scope.mySelections = [];
$scope.gridOptions = { 
  data: 'myData',
  selectedItems: $scope.mySelections,
  multiSelect: false
};

Then $scope.mySelections would hold an array with 1 item in multiSelect:false.

Check out this page: http://angular-ui.github.io/ng-grid/ for further reference.

Upvotes: 3

Related Questions