[英]Get only visible columns when selecting a row in angular ui-grid
我想在angular-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中的所有列。 我不要隱藏的列。 我怎么做? 請幫忙。
您可以在選定列/可見列的基礎上調制列。 你可以有這樣的代碼-
$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();
};
在此處查找更新的柱塞
希望它能解決您的問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.