MOHAN V
MOHAN V

Reputation: 46

How to export Html.Kendo().Grid data to excel in generic way using javascript ?

Please find the kendo grid code sample code in the view.

I am binding the data to the grid from the model , I need to export the grid data to the excel file on click of a button ... please suggest..

 @(Html.Kendo().Grid<Model>().Name("grid")
                        .Columns(columns =>
                        {

                            columns.Bound(p => p.field1).Width(20);
                            columns.Bound(p => p.field2).Width(50);
                            columns.Command(commands =>
                            {
                                commands.Edit(); 
                            }).Width(20);
                        }).Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
                                                    .Pageable(pageable =>                 pageable.ButtonCount(5)).Sortable()
                                                    .DataSource(dataSource => dataSource.Ajax()
                                                            .Read(read => read.Action("LoadData", "Mycontroller")).PageSize(10)
                                                    .Model(model => model.Id(d => d.Id))
                                                    .Update(update => update.Action("UpdateData", "Mycontroller").Type(HttpVerbs.Post))))

Upvotes: 1

Views: 909

Answers (1)

Lőrincz P&#233;ter
Lőrincz P&#233;ter

Reputation: 160

First you need to include the excel toolbar by adding the following line: .ToolBar(tools => tools.Excel()) After that you can add the following : .Excel(excel => excel .FileName("Kendo UI Grid Export.xlsx") .Filterable(true) )

Upvotes: 2

Related Questions