简体   繁体   中英

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))))

首先,您需要通过添加以下行来包括excel工具栏: .ToolBar(tools => tools.Excel())之后,您可以添加以下内容: .Excel(excel => excel .FileName("Kendo UI Grid Export.xlsx") .Filterable(true) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM