2016-02-24 36 views
1

我有一個表UI電網完成,此表導出CSV有這樣cellFilter定義列:從UI的網格單元格顯示而不是源值

{ field: 'company', cellFilter: 'mapCompany:row.grid.appScope.companyCatalog' } 

我gridMenu定製產品配置是這樣的:

gridMenuCustomItems: [ 
     { 
      title:'Custom Export', 
      action: function ($event) { 

       var exportData = uiGridExporterService.getData(this.grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL, true); 

       var csvContent = uiGridExporterService.formatAsCsv([], exportData, this.grid.options.exporterCsvColumnSeparator); 

       uiGridExporterService.downloadFile (this.grid.options.exporterCsvFilename, csvContent, this.grid.options.exporterOlderExcelCompatibility); 

      }, 
      order:0 
     } 
    ] 

表顯示正常,但是當我嘗試導出爲CSV,公司列出口與空值。這是我的Plunkr

任何建議將appretiated

參考

我做了一些研究,並根據ui-grid Issue #4948當公司中填入一個靜態目錄它的作品好。這是一個Plunkr解釋這一點。

回答

0

我找到了CSV導出的解決方案,能夠顯示單元顯示值。 我的錯誤是使用row.grid代替this.grid在mapCompany細胞過濾器:

columnDefs: [ 
    { field: 'name' }, 
    { field: 'company', cellFilter: 'mapCompany:row.grid.appScope.companyCatalog' } 
], 

使用它的正確方法是使用這樣的:

columnDefs: [ 
    { field: 'name' }, 
    { field: 'company', cellFilter: 'mapCompany:this.grid.appScope.companyCatalog' } 
], 

這是我Plunkr

1

正如你提到的,出口的問題時,該列中的值不是靜態的,所以我forked your plunker與創建每個數據對象的公司映射並將它作爲一個鍵值,一旦你得到了一個解決方案公司目錄回:

$http.get('https://api.github.com/users/hadley/orgs') 
    .success(function(data) { 

    $scope.companyCatalog = data; 
    angular.forEach($scope.gridOptions.data, function(item) { 
     var compMap = uiGridFactory.getMapCompany(item.company, $scope.companyCatalog); 
     item.mappedCo = compMap; 
    }); 
    }); 

我已經把原來的公司列,但使它不可見(而不是覆蓋它),因此它與導出數據的CSV休息。新柱DEFS:

columnDefs: [ 
    { field: 'name' }, 
    { field: 'mappedCo', name: 'Company'}, 
    { field: 'company', visible: false } 
] 

而且,在你從服務器獲取數據的情況下,你必須確保你運行映射函數之前的數據和目錄返回。此解決方案可能無法在您的特定用例中起作用;我不知道。

+1

你好亞當斯。謝謝你的建議!在我的特殊情況下,我考慮了一個類似於你提出的這個選項的選項,但我不想創建一個虛假的列,因爲我有很多類似問題的網格。如果我在一個月內找不到解決方案,我想我會使用這種方法。 – Aquiles

相關問題