This is a migrated thread and some comments may be shown as answers.

Using bearer auth token on excel export Kendo MVC

4 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MOZ
Top achievements
Rank 1
MOZ asked on 09 Mar 2021, 06:09 PM

Hello 

I'm using an external api for my grid datasource, for authorization I'm using this solution:

https://www.telerik.com/forums/asp-net-core-custom-datasource-pass-bearer-token

and is working fine for read event.

 $(() => {
        var grid = $("#grid").data("kendoGrid");
        grid.dataSource.transport.options.read.beforeSend = beforeSendHandler;
    });

But unfortunately is not working in Excel Export option, apparently is creating a new web request that doesn't follow the beforeRequest function flow. 

Is it possible to add the header to the export request or should I create be a custom action?

 

Greetings 

4 Answers, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 12 Mar 2021, 02:21 PM

Hello,

Thank you for the details provided.

In order to achieve the desired behavior, I would recommend using the "excelExport" Event of the Kendo UI Grid. 

Use the function handler of the Event, make the needed tests, and preventDefault behavior if needed.

Find more information about the Excel Export in the following article:

I hope this information helps.


Kind Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
MOZ
Top achievements
Rank 1
answered on 19 Mar 2021, 09:44 PM

Hello Anton

I tried the approach you're suggesting but the excelExport event is for files configuration purposes and it triggers after the requests, it's like the saveAsExcel() function is not using the beforeRequestHandler function on the datasource transport options. 

Regards.

0
MOZ
Top achievements
Rank 1
answered on 22 Mar 2021, 07:55 PM
Hello there.
I managed to set the beforeSend option overriding the excel/kendo-excel definition and adding this line:


this.dataSource.transport.options.read.beforeSend = beforeSendHandler;


After creating the new excelExporter, either way, if there's an easier way to do this, I will appreciate it to let me know. 


Thank you in advance.
0
Accepted
Anton Mironov
Telerik team
answered on 24 Mar 2021, 03:04 PM

Hello,

You are totally correct this approach is an excellent decision.

Another one that I would recommend is handling the "click" event of the Excel export button. Prevent the default behavior, implement the needed logic and then manually force the export functionality.

I hope this information helps. Let me know if I should look for another solution, or if further assistance is needed.

 

Best Regards,
Anton Mironov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
MOZ
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
MOZ
Top achievements
Rank 1
Share this question
or