Devextreme: ODataStore based Data-grid Server-side excel export

Created on 17 Apr 2019  路  7Comments  路  Source: DevExpress/DevExtreme

Steps to Reproduce:

I have a data-grid based on ODataStore on Angular 7 SPA. I'm dynamically creating a DataGrid by getting all grid and store options from an Api. I want to export grid data as an excel file from server-side, because, I have too much data to export from client-side (too much is that chrome crashes while processing it). So i created a Result filter in backend, it changes response type to excel file when odatastore wants to export data.

Results You Received:

There are some issues i can't resolve.
1) If i manipulate and create a new http request in odatastore beforeSend method for download exported data, I'm getting 2 excel file. Because, i can't cancel main oDataStore export request and it's coming empty cause i have changed the response type by my custom result filter.

2) If i use datagrid onExporting method to create a new export request and cancel exporting, I can't get odata query from datagrid or odatastore. So i cant use my odata api's to export.

Results You Expected:

1) Is there any acceptable escape scenerio or cancellation token for beforeSend method?
2) I have checked the devextreme repository, ODataStore have a query adapter to apply grid filters as OData query. So, Can i use Query adapter in my app to get oData query from filter builder or datagrid filters?

Environment Details:

.net Core Api 2.2
Angular 7 SPA
devextreme : 18.2.3
devextreme-angular : 18.2.3

typquestion

Most helpful comment

We are following with curiosity.

All 7 comments

We are following with curiosity.

I hope the solution will be offered as soon as possible.

Shouldn't you ask this question on https://github.com/OData/WebApi page?

Shouldn't you ask this question on https://github.com/OData/WebApi page?

I think, i should resolve the problem with devextreme tools, because, i have no issue on odata, it gives me data as json or as excel file (thanks to my result filter).
I need to split download request from normal odata call. In these two solution i wrote, i got so close, but could not succeed. (but if there is a js lib to convert devextreme filters to odata queries, it can resolve the problem)

Hello @ynslmz

We need more details about the following part:

If i manipulate and create a new http request in odatastore beforeSend method

Would you please share a code sample that illustrates the approach you are implementing?
Probably, the issue can be solved by manipulating Promise objects within the beforeSend handler, but we cannot be specific without seeing the code.

Simple runnable project would be ideal.
Upload it here or open a Support ticket.

Hi @AlekseyMartynov,

Here is my sample code. I have no runnable code for you but this can give you a clue.

```export class ReportingService {

constructor(private tokenService: TokenService, private config: ConfigService, private apiService: ApiServiceClient) { }

GetReportODataStore(apiUrl: string, apiId?: number): any {
    return new ODataStore({
        beforeSend: (data) => {
            data.headers = { 'Authorization': 'Bearer ${this.tokenService.getToken().access_token}' };
            if (!(data.params.$top && data.params.$count)) {
                this.getReportInExcell({ params: data.params, url: data.url });
                // I need a logic to cancel store's own request here
            }
        },
        version: 4,
        url: this.config.apiUrlById(apiId, apiUrl).replace('api/v1.0', 'odata'),
        onLoading: (options) => {
            if (options.filter) {
                options.filter = this.IsoDateEncoder(options.filter);
            }
        },
        deserializeDates: true
    });
}

```

Thanks for your help.

In the beforeSend handler, you cannot cancel the request. You can only customize request details (url, etc) which is usually enough.

If you need to completely rewrite the load logic, use a subclass:

import ODataStore from "devextreme/data/odata/store";
import { LoadOptions } from "devextreme/data/load_options";

class CustomizedStore extends ODataStore {
    load(options?: LoadOptions) {
        if(!(options.take && options.requireTotalCount)) {
            return new Promise((resolve, reject) => {

            });
        }
        return super.load(options);
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JuFrolov picture JuFrolov  路  9Comments

bbakermmc picture bbakermmc  路  7Comments

yeganesalami picture yeganesalami  路  8Comments

Yura13 picture Yura13  路  8Comments

Walgermo picture Walgermo  路  4Comments