获取 uiGrid 中选定行的值 angular

Getting values of the selected row in uiGrid angular

我有一个 ui 网格,它允许用户选择一行。如果选择了一行,我想将所选行的某些字段绑定到输入字段。这怎么可能?

$scope.gridOptions = {
data : items,
columnDefs: [
  { name: 'ITEMNO', field: 'ITEMNO', displayName: 'Pos.', enableHiding : false, width: 75 },
  { name: 'SERIALN_REQ', field: 'SERIALN_REQ', displayName: 'Serialpflichtig', enableHiding : false, width: 175  }
],
enableScrollbars : false,
enableHorizontalScrollbar : 0,
enableVerticalScrollbar : 0,
enableFullRowSelection : true,
enableRowSelection: true,
enableSelectAll: false,
multiSelect : false,
selectionRowHeaderWidth: 0,
rowHeight: 55,
enablePaginationControls: false,
paginationPageSize: 5

};

  $scope.gridOptions.onRegisterApi = function (gridApi) {
    $scope.gridApi = gridApi;
    $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
    $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
    var rows = $scope.gridApi.selection.getSelectedRows();
  }

在我的 HTML 中,我有以下内容:

<div class="large-2 columns">
    <input type="text" disabled ng-model={{}}> <!-- here i want to bind a cell of the selected grid row -->
  </div><div ui-grid="gridOptions" ui-grid-selection ui-grid-pagination class="myGrid"></div>

这是您预期的(获取选定的行值并将它们绑定到输入元素)。

使用下面的代码

$scope.rowtobebinded=undefined;
$scope.gridOptions.onRegisterApi = function(gridApi) {
        $scope.gridApi = gridApi;
        $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
        $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
        var rows = $scope.gridApi.selection.getSelectedRows();

        //aravind's code to get the selected row elements is as below
        gridApi.selection.on.rowSelectionChanged($scope,function(row){
                console.log("selected row is ",row);

               //binding the row's no to the textbox

                $scope.rowtobebinded=row.entity.ITEMNO; 

        });
});

LIVE DEMO