Hello,
I've been reading up on the documentation about the customisation of exported excel documents from the grid. My project is an MVC applicaation using razor views. My question is how do you marry the grid to the javascript so that when the user presses "export" it runs the function?
For example my grid looks like this:
@(Html.Kendo().Grid<Widget_Tests.Models.tbl_data>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.old_id).Title("Old ID");
columns.Bound(c => c.name).Title("Name");
columns.Bound(c => c.type).Title("Vessel Type");
columns.Bound(c => c.company).Title("Company");
}
)
.ToolBar(toolbar =>
{
toolbar.Excel();
}
)
.Pageable()
.Scrollable()
.Excel(excel => excel
.FileName("MyGrid.xlsx")
.AllPages(true)
.Filterable(true)
)
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.Read(read => read.Action("tbl_data_Read", "Home"))
)
)
Here is the javascript I found in the documentation:
function saveExcel() {
var workbook = new kendo.ooxml.Workbook({
sheets: [
{
columns: [{ autoWidth: true }],
rows: [
{
cells: [
{
value: "bold and italic",
bold: true,
italic: true
}
]
},
{
cells: [
{
value: "red text on blue background",
color: "#ff0000",
background: "#0000ff"
}
]
},
{
cells: [
{
value: "Arial 20px",
fontSize: 20,
fontName: "Arial"
}
]
},
{
cells: [
{
value: "Right aligned",
hAlign: "right"
}
]
},
{
cells: [
{
value: "Centered horizontally and vertically",
vAlign: "center",
hAlign: "center",
rowSpan: 2
}
]
}
]
}
]
});
};
kendo.saveAs({
dataURI: workbook.toDataURL(),
fileName: "Test.xlsx"
});
How do these go together?