2017-04-04 2 views
1

Je souhaite sélectionner une ligne dans la grille angulaire-ui et copier la ligne dans le plan de découpe.Afficher uniquement les colonnes visibles lors de la sélection d'une ligne dans le quadrillage angulaire

Ceci est mon code:

$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

Cependant, je veux juste copier les colonnes visibles, mais je reçois toutes les colonnes qui sont dans le JSON. Je ne veux pas les colonnes cachées. Comment je fais ça? S'il vous plaît aider.

+0

pouvez-vous ajouter un violon? –

+0

@MuhammedNeswine J'ai édité ma question –

Répondre

2

Vous pouvez moduler les colonnes sur la base des colonnes/colonnes visibles sélectionnées. vous pouvez avoir un code comme celui-ci -

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

Trouver Mise à jour Plunker Here

espère que ça va résoudre votre problème!

+0

Merci Bro, cherchait la même chose :) –