0
votes

How to set up kendo Grid with MVC extensions not do additional request when export to excel?

Here is grid definition. The problem is when export to excel button is clicked grid make additional request to server, it is needed to export displayed data without request.

@(Html.Kendo()
    .Grid<VmTaskItem>()
    .Name("kTasks")
    .Columns(c => {
        c.Bound(m => m.TaskType).Title().Width(150);
    })
    .ToolBar(tb => tb.Excel())
    .Excel(e => e
        .AllPages(false) // must disable request when export
    )
    .DataSource(ds => ds
        .Ajax()
        .PageSize(30)
        .Read(r => r.Action("GetTaskItems", "Home")
        .Type(HttpVerbs.Get))
    ))

From documentation https://docs.telerik.com/aspnet-mvc/helpers/grid/excel-export

When the AllPages option is set to true the Grid makes a read request for all data.

Also, at demo page for MVC Grid make addition request when export to excel
http://demos.telerik.com/aspnet-mvc/grid/excel-export
at demo page for Grid without MVC did not
http://demos.telerik.com/kendo-ui/grid/excel-export

1

1 Answers

0
votes

The export functionality will query the data before doing the export.

The MVC demo makes a read request because the razor Grid helper defaults to use server operations if you do not specify it whereas the javascript initialization defaults to false.

If you explicitly add .ServerOperation(false) to your .DataSource config,

.DataSource(ds => ds
    .Ajax()
    .PageSize(30)
    .Read(r => r.Action("GetTaskItems", "Home")
    .Type(HttpVerbs.Get))
    .ServerOperation(false)
))

it should not make a request before exporting the data, but it will only export the current page.

If you need server operations AND not hit the server before export...you may have to override the built-in export and implement it yourself.