在角度 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();
  };

在这里找到更新的Plunker

希望它能解决你的问题!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

角度ui-grid网格高度/行可见

来自分类Dev

ui-grid角度事件:已选择行

来自分类Dev

角度ui-grid-下拉选择显示ID

来自分类Dev

角度ui-grid分组头

来自分类Dev

角度ui-grid:更改总和的标签

来自分类Dev

角度ui-grid外部导出按钮

来自分类Dev

角度ui-grid分组头

来自分类Dev

对象的角度ui-grid分组

来自分类Dev

在有角度的ui-grid中使行选择成为条件

来自分类Dev

用复选框替换有角度的UI-GRID选择RowButton

来自分类Dev

如何自定义角度 ui-grid 行背景颜色?

来自分类Dev

角度ui选择图像

来自分类Dev

选择过滤器ui-grid之后的第一个可见行

来自分类Dev

角度ui网格行选择

来自分类Dev

如何在角度ui-grid中显示从json到ui-grid的数据

来自分类Dev

单元标题中的角度ui-grid事件未触发

来自分类Dev

在角度ui.grid中动态更改网格选项

来自分类Dev

角度ui-grid动态计算网格高度

来自分类Dev

隐藏水平滚动条(角度ui-grid)

来自分类Dev

无法找到适合角度安装UI-GRID的版本

来自分类Dev

角度ui-grid显示HTML Unicode字符

来自分类Dev

角度1.5.0。通过ocLazyLoad用UI GRID重新加载页面时,根模板是重复的。$$ animateJs未定义

来自分类Dev

角度UI网格单击行

来自分类Dev

角度ui-grid / ng-grid滤镜更改触发频率太高

来自分类Dev

UI-Grid中的角UI选择?

来自分类Dev

UI-Grid 行聚合

来自分类Dev

ui.grid行无法选择行

来自分类Dev

如何在UI-grid表中仅使expandale仅一行

来自分类Dev

角度UI选择突出显示HTML