2016-12-13 2 views
0

사용자가 하나의 행을 선택할 수있는 UI 그리드가 있습니다. 행을 선택하면 선택한 행의 일부 필드를 입력 필드에 바인딩합니다. 이것이 어떻게 가능한지?uiGrid에서 선택된 행의 값 얻기

$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 

}};

다음
<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> 
+0

를 사용? – Aravind

+0

안녕하세요; 나는 여기에있는 실행 플 런커를 준비했다 : https://plnkr.co/edit/lmoKaMozQQ569n71G5C8?p=preview – user1829716

+0

내 대답을 체크 아웃 – Aravind

답변

1

이 예상 한 (행 값을 선택 얻을 및 입력 요소에 바인딩)입니다 : 내 HTML에서

$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(); 
    } 

난 다음 있습니다.

유 작업 plunker를 만들 수 있습니다 아래의 코드

$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

+0

어이 aravind,이 날 많이 도움이됩니다. 양방향 바인딩을 사용하는 방법이 있나요? 그래서 입력 필드의 변경 사항이 그리드와 workdata.items 배열에서 직접 변경됩니다. 그렇지 않으면 나는 사건 처리사와 함께 그것을 깨달을 수있다. 도와 줘서 고마워! – user1829716

+0

멋지 네. 너를 도와 줘서 고맙다. 당신은 상세하게 당신의 질문을 정교하게 만들 수 있습니까? – Aravind

+0

나는 모바일이므로 해결책을 찾을 수 없습니다. 시도 할 것이다. – Aravind