在angularjs中选择特定的列

在angularjs中选择特定的列

本文介绍了在angularjs中选择特定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web项目.它在客户端使用angularjs.要求之一是在网格中显示一些数据,并提供选项以将数据导出到csv文件中.

I am working on a webproject. It is using angularjs on clientside.One of the requirement is to display some data in a grid and give options to export the data into csv file.

我正在尝试使用ngCsv模块来实现此功能.我在集合中的网格中显示数据.在显示时,我可以控制要显示的列.但是,在将数据导出到CSV时,我只能使用集合.当我使用集合时,它将导出集合中导出的csv文件中的所有列.但是我只想导出特定的列.可能有一种方法可以从angularjs的集合中仅选择特定的列,但是我找不到方法.

I am trying to use ngCsv module for this functionality. I display data in the grid from a collection. While displaying I have control on what columns I can display. But while exporting the data to CSV all that I can use is the collection. When I use the collection it is exporting all the columns from the collection in the exported csv files. But I want to export only specific columns. There may be a way to select only specific columns from the collection in angularjs but I could not find a way to do it.

这是在控制器上加载应用的功能

This is the function that loads apps on the controller

function loadApps()
{
    appService.getApps().then(function (result) {
    vm.assets = result.data.items;});
}

此功能用于导出应用

vm.exportApps = function () {
        return vm.apps.filter(function (a) {
            return a.selected;
        });
    }

这是来自html

<button class="btn btn-sm btn-primary" ng-csv="vm.exportApps" filename="SelectedAppsList.csv">Export Apps </button>

有人可以建议我只选择要导出的特定列吗?

Can somebody suggest as to what I can do to just select specific columns to export ?

推荐答案

您可以尝试在HTML代码中使用 csv-column-order 属性.

You can try to use csv-column-order attribute in your html code.

<button class="btn btn-sm btn-primary" ng-csv="vm.exportApps" csv-column-order="vm.columns" filename="SelectedAppsList.csv">Export Apps </button>

并指定您需要哪些列

vm.columns = function () {
    return ['column1', 'column2', 'column3'];
};

它们来自您的对象数组

vm.apps = [{column1:10, column2:12, column3:13}, {column1:14, column2:15, column3:16}]

这篇关于在angularjs中选择特定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:03