Reputation: 46
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
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