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

Custom Export...

1 Answer 490 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 03 Aug 2016, 05:31 PM

I have a scenario where the grid contains a small subset of the fields in a table.  When I export to excel, I want to include the extra fields.  But there are so many extra fields, and the export is used infrequently, that I don't want the overhead of always including them as hidden columns.  What I'd like to do is construct the excel file on the server, and feed it back to the client.  I have the grid set up to use the server proxy for the excel export as follows:

@(Html.Kendo().Grid<InstID2.Models.Institution>()
    .Name("grdInstitutions")
    .ClientDetailTemplateId("client-template")
    .Pageable()
    .Sortable()
    .Filterable()
    .ToolBar(t => t.Excel())
    .Excel(excel => excel
        .FileName("Kendo UI Grid Export.xlsx")
        .Filterable(true)
        .ProxyURL(Url.Action("Excel_Export_Save", "Default"))
        .ForceProxy(true)
    )
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Institution_Read", "Default"))
        )
    )
)

And I have the server proxy action as follows:

        public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
        {
            var fileContents = Convert.FromBase64String(base64);

            return File(fileContents, contentType, fileName);
        }

 

So I have 2 questions:

 

1.  To construct the excel file on the server, the server needs to know the current grid filters that are applied.  Is there a way to pass the current filters in as a parameter to the ProxyURL?  I've tried a few variations using a javascript function, but nothing has worked so far.

 

2.  Since the server will be executing a query and constructing the excel file, the export data passed from the client (the "base64" parameter above) is not needed.  Is there a way to make the client skip creating and sending the export data to the server?  This is a minor issue as the parameter can simply be ignored.  But it would improve performance if the client could skip that step since it is not needed.

 

Thanks,

 

Ray

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 05 Aug 2016, 02:16 PM

Hello Raymond,

My suggestion is to review the Server-side Excel export project. It demonstrates how to export the Kendo UI Grid data as an Excel document on the server side. Main advantage of server-side export is that it allows the developer full control over the final output.

Regards,
Boyan Dimitrov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Raymond
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or