107
Views
12
Comments
Solved
[OutSystems Data Grid Web] Unable to customize "ExportCSV" functionality in Outsystems Data Grid Web
outsystems-data-grid-web
Web icon
Forge asset by OutSystems
Application Type
Traditional Web

Hello,

I am trying to customize the functionality of Export CSV from Outsystems Data Grid Web. I want to involve the hidden columns as well while exporting the CSV. In order to do so, I figured out that I need to make changes to "GridOS.ExcelFeature.exportCSV" and "GridOS.ContextMenuFeature._copy" functions. So, I copied these 2 functions added them into Javascript and did the required change in those functions. 

But while calling the function "GridOS.ExcelFeature.exportCSV" I am getting the below error,

I called it the same way it has been called on the data grid web component itself,


Changes done by me are:

1. "GridOS.ContextMenuFeature._copy"  -> Commented highlighted lines

2. "GridOS.ExcelFeature.exportCSV"  -> Called the new _copy function which has the above highlighted code instead of existing one.

Can anybody please help me here. Thanks in advance.


2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Harsh Sharma 

I was able to find a solution and to be honest after trying two different approaches, I think this will be the best solution.

Assumptions:

  • you need to have all the columns you want to have on the exported CSV as column blocks and with the property Hide=true so that the columns are created on the Columns Collection:
  • the row header will always be included, so a blank column will be seen on the exported Excel - this is a rule from Wijmo that in the future can change but currently there's no way to avoid

Solution:

  • Wrote a different method to use the object ClipStringOptions (find the oml attached):
/* Create export all to CSV 
Using ClipStringOptions */

function exportAllToCSV (gridId,filename) {    
    
    var gObj = GridOS.ComponentUtils.getGridObjectById(gridId);

    // add a filter to show that it works while exporting
    var f = new wijmo.grid.filter.FlexGridFilter(gObj.grid);

    var options = wijmo.grid.ClipStringOptions.CSV;
    options ^= wijmo.grid.ClipStringOptions.InvisibleColumns;

    var rng = new wijmo.grid.CellRange(0, 0, gObj.grid.rows.length - 1, gObj.grid.columns.length - 1),
    csv = gObj.grid.getClipString(rng, options, true, true);
    exportFile(csv, filename);

}

//Export the file
function exportFile(csv, fileName) {
    var fileType = 'txt/csv;charset=utf-8';
    if (navigator.msSaveBlob) { // IE 
      navigator.msSaveBlob(new Blob([csv], {
        type: fileType
      }), fileName);
    } else {
      var e = document.createElement('a');
      e.setAttribute('href', 'data:' + fileType + ',' + encodeURIComponent(csv));
      e.setAttribute('download', fileName);
      e.style.display = 'none';
      document.body.appendChild(e);
      e.click();
      document.body.removeChild(e);
    }
  }

Hope it helps.

Cheers,
GM

ExportAllColumns_Workaround.oml
2025-10-18 11-13-53
Ramesh subramanian

Hi Harsh Sharma,

Please check this link and get some idea. because same case. 

https://www.outsystems.com/forums/discussion/79965/how-to-export-excel-without-hidden-columns-in-data-grid-web/

thanks,

Ramesh

UserImage.jpg
Harsh Sharma

Hi Ramesh,

In my case I want to export the excel with all the columns irrespective of their visibility and I think the above link that you have provided has some different scenario. Thank you.

2022-07-19 16-56-14
Giuliana Silva
Staff

Hi, @Harsh Sharma!


To export the CSV with all the columns, try to use the following code:

GridOS.ExcelFeature.exportCSV(gridID, null, { 

        fileName: 'FlexGrid.csv', 

        includeColumns: function(column) { return  true; } 

});

If you want to export the Excel, you can use the ExportExcelButton that exports all columns by default, but the ones that are not visible of the DataGrid will be hidden in the excel file.


Hope it helps,

Giuliana.

UserImage.jpg
Harsh Sharma

Hi @Giuliana Silva ,

I tried the above approach, but it is also downloading the columns which is visible in current view only not all of them. I included this code in the Run Javascript action. Hope I did expectedly.

Can you please suggest any alternative to achieve this.

2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Harsh Sharma 

By looking at the Wijmo documentation can you please share what you've tried so far on top of what Giuliana shared?

UserImage.jpg
Harsh Sharma

Hi @Gonçalo Martins ,

I tried the approach which Giuliana shared by putting the code in a Run Javascript action which will trigger on click of a button. 

Also, I tried to customize the functions for exporting the csv written in GridFramework.JS of Data grid web component. By doing the changes mentioned in question above, now I was able to achieve all the cells of hidden columns as well but not getting the headers of those hidden columns. So, I tried using "includeColumnHeaders" and "includeRowHeaders" from wijmo doc but that didn't work for me.

Referring to below screenshot I am not getting the headers but all the cells of those columns

2022-07-19 16-56-14
Giuliana Silva
Staff

Hi @Harsh Sharma,

As I could not reproduce this issue on my side, could you please share a file reproducing this behavior, so I can assist you better?

Thanks,

Giuliana.

UserImage.jpg
Harsh Sharma

I think what Giuliana shared didn't work for me because wijmo.savefile only expects params.filename to be passed. Is there any other way to pass those parameters named "includeColumns".


2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Harsh Sharma 

In order to use Giuliana's code you need to override the exportCSV function.
By doing that you can change the method on the page level and use the includeColumns which is what you need to achieve your use case. Can you share your sample oml?

UserImage.jpg
Harsh Sharma

Below is my OML attached for the above use case. I tried to override the function at the page level and called the overriden function using RunJavascript action containing the code shared above to include columns. Please check.

ExportAllColumns.oml
2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Harsh Sharma 

I think I understood the issue but am not sure about the solution - will need to get some time to investigate. It seems that the includeColumns is only used for Excel export and the code always looks at the page view so we can only get the columns that are rendered since they're the ones we can access by looking at gObj.grid.column like the method that is implemented. Once I have some time throughout the week I'll try to find a way of doing this if possible. If you find some examples of this use case on Wijmo's documentation please share them since it will be easier to understand if we can do it and how.

2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Harsh Sharma 

I was able to find a solution and to be honest after trying two different approaches, I think this will be the best solution.

Assumptions:

  • you need to have all the columns you want to have on the exported CSV as column blocks and with the property Hide=true so that the columns are created on the Columns Collection:
  • the row header will always be included, so a blank column will be seen on the exported Excel - this is a rule from Wijmo that in the future can change but currently there's no way to avoid

Solution:

  • Wrote a different method to use the object ClipStringOptions (find the oml attached):
/* Create export all to CSV 
Using ClipStringOptions */

function exportAllToCSV (gridId,filename) {    
    
    var gObj = GridOS.ComponentUtils.getGridObjectById(gridId);

    // add a filter to show that it works while exporting
    var f = new wijmo.grid.filter.FlexGridFilter(gObj.grid);

    var options = wijmo.grid.ClipStringOptions.CSV;
    options ^= wijmo.grid.ClipStringOptions.InvisibleColumns;

    var rng = new wijmo.grid.CellRange(0, 0, gObj.grid.rows.length - 1, gObj.grid.columns.length - 1),
    csv = gObj.grid.getClipString(rng, options, true, true);
    exportFile(csv, filename);

}

//Export the file
function exportFile(csv, fileName) {
    var fileType = 'txt/csv;charset=utf-8';
    if (navigator.msSaveBlob) { // IE 
      navigator.msSaveBlob(new Blob([csv], {
        type: fileType
      }), fileName);
    } else {
      var e = document.createElement('a');
      e.setAttribute('href', 'data:' + fileType + ',' + encodeURIComponent(csv));
      e.setAttribute('download', fileName);
      e.style.display = 'none';
      document.body.appendChild(e);
      e.click();
      document.body.removeChild(e);
    }
  }

Hope it helps.

Cheers,
GM

ExportAllColumns_Workaround.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.