151
Views
4
Comments
Solved
[OutSystems Data Grid] Export filtered grid
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive
Service Studio Version
11.54.20 (Build 62656)

Hi,

I have the following DataGrid in my Homepage:

FoodName | ProducerName | ID
-----------------+------------------------+-----
Pasta           |  Barilla                |  1

Now the Entity Food doesn't have only the informations I show in this DataGrid, but also a bunch of other columns, most of which are a reference to other entities.

This DataGrid can be filtered and my requirements are to Export as an Excel not only the informations shown in the filtered DataGrid, but all the informations bound to every entity of Food.

For example if a filter per FoodName = Pasta, the expected output should be not only {Pasta, Barilla, 1} but the expected columns in the excel should be something like {FoodName, ProducerName, ExpirationDate, ProducedOn, ID} .

I cannot modify the structure of the DataGrid, also because the informations to retrieve are way to much to join every table needed and to build the DataGrid with all the necessary missing columns by hand.

The DataGrid has also pagination, so on the DataGrid's page are not always shown all the records that meet the filters.

It is possible to filter on multiple columns and not all the columns contain text value.

Is there a way to achieve this? Or to retrieve the filtered columns, so that I can do a SLQ Query to retrieve the information needed based on the IDs?

2025-07-09 07-52-36
Raffaele Battipaglia
Solution

One of my collegues suggested a possible solution that, for the moment, seems to work.
I'll leave it here as a solution for future references, but keep in mind that it uses a protected property of the Grid.provider.itemsSource class.

Assuming the DataGrid is fed by a StructureX List, where StructureX holds all the columns that are shown in the DataGrid, the following JS retrieve all the data inside the filtered grid as a JSON:

The result is then Deserialized:












From here, you can just get the IDs or other informations needed to perform more advanced tasks from the List.

I hope this can help while finding a better solution.

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

Hello @Raffaele Battipaglia

We can provide a possible workaround using the available APIs since this is something that the OS Data Grid doesn’t offer it directly.

  • In the Grid OnInitialize event, add a JavaScript node with the following script:

    OutSystems.GridAPI.GridManager.GetGridById($parameters.GridWidgetId).features.export.exportToExcel = 
        function (withStyles, filename) {
            this._resetPagination();
            if (this._hasLoadingMessage) {
                this._showLoadingMessage();
            }
            setTimeout(() => {
                const params = {
                    includeColumnHeaders: true,
                    includeRowHeaders: true,
                    includeStyles: withStyles,
                    formatItem: this.exportFormatItem,
                    includeColumns: function(column) { return (column.binding != "Id" && column.binding != "Rate" && column.binding != "Description") }
    
    
                };
                const book = wijmo.grid.xlsx.FlexGridXlsxConverter.save(this._grid.provider, params);
                book.sheets[0].name = 'DataGrid Data';
                book.save(this._handleFilename(filename, false));
                this._reApplyPagination();
                if (this._hasLoadingMessage) {
                    this._removeLoadingMessage();
                }
            }, 10);
        }
    		

Hope it helps!

Cheers,
GM

2025-07-09 07-52-36
Raffaele Battipaglia

Thank you for your answer,
Can you please explain me what this code accomplishes?

I tried to Export As Excel the table and nothing has changed in the Excel, did I miss something?

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

As you can see, it overrides the exportToExcel which is the method used by OS Data Grid to export to Excel and allow you to select the columns to export.

2025-07-09 07-52-36
Raffaele Battipaglia
Solution

One of my collegues suggested a possible solution that, for the moment, seems to work.
I'll leave it here as a solution for future references, but keep in mind that it uses a protected property of the Grid.provider.itemsSource class.

Assuming the DataGrid is fed by a StructureX List, where StructureX holds all the columns that are shown in the DataGrid, the following JS retrieve all the data inside the filtered grid as a JSON:

The result is then Deserialized:












From here, you can just get the IDs or other informations needed to perform more advanced tasks from the List.

I hope this can help while finding a better solution.

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