2017-04-04 7 views
1

角度-uiグリッドの行を選択し、その行をクリップボードにコピーしたいとします。角度uiグリッドで行を選択するときに表示される列のみを取得する

これは私のコードです:

$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:http://plnkr.co/edit/dcj7DUWHyA3u1bouxRhI?p=preview

しかし、私はちょうど目に見える列をコピーしたいが、私はJSONにあるすべての列を取得しています。私は隠しコラムがほしくない。それ、どうやったら出来るの?助けてください。

+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

ありがとうBroは、同じを探していた:) –

関連する問題