2017-04-04 9 views
1

각도 -ui 눈금에서 행을 선택하고 행을 클립 보드에 복사하고 싶습니다. 난 그냥 눈에 보이는 열을 복사하려면, http://plnkr.co/edit/dcj7DUWHyA3u1bouxRhI?p=preview각도 ui-grid에서 행을 선택할 때 보이는 열만 가져옵니다.

그러나,하지만 난 JSON에있는 모든 열을 얻고있다 :

$scope.copySelection = function() { 
    $scope.retainSelection = $scope.gridApi.selection.getSelectedRows(); 
    alert(JSON.stringify($scope.retainSelection)); 
    var input = document.createElement("input"); 
    input.type = "text"; 
    document.getElementsByTagName('body')[0].appendChild(input); 
    input.value = JSON.stringify($scope.retainSelection); 
    input.select(); 
    document.execCommand("copy"); 
    input.hidden = true; 
    $scope.gridApi.selection.clearSelectedRows(); 
    }; 

Plunker :

이 내 코드입니다. 나는 숨겨진 칼럼을 원하지 않는다. 어떻게해야합니까? 도와주세요.

+0

바이올린을 추가 할 수 있습니까? –

+0

@MuhammedNeswine 내 질문을 편집했습니다 –

답변

2

선택한 열/보이는 열을 기준으로 열을 변조 할 수 있습니다. 이 같은 코드를 가질 수 -

$scope.copySelection = function() { 

    $scope.retainSelection =angular.copy($scope.gridApi.selection.getSelectedRows()); 

    angular.forEach($scope.retainSelection,function(value,key){ 
     var columndef=angular.copy($scope.gridOptions.columnDefs); 
     for (var property in value) { 
     if (!(value.hasOwnProperty(property) && columndef.filter(function(a){return a.name.split('.')[0]===property}).length>0)) { 
     delete value[property]; 
     } 
    } 

    }); 
    alert(JSON.stringify($scope.retainSelection)); 
    var input = document.createElement("input"); 
    input.type = "text"; 
    document.getElementsByTagName('body')[0].appendChild(input); 
    input.value = JSON.stringify($scope.retainSelection); 
    input.select(); 
    document.execCommand("copy"); 
    input.hidden = true; 
    $scope.gridApi.selection.clearSelectedRows(); 
    }; 

이 Plunker Here

업데이트는 문제를 해결할 것입니다 희망합니다!

+0

감사합니다 형, 같은 찾고있었습니다 :) –