function exportChartToGrid(ds, name, colNames, title) {
// $("#main-content") replace with your main container id or can use class selector
var element = $("#main-content").find("#gridExport"); // append element only when not present
if (element.length === 0) $("#main-content").append("<div style='display:none !important;' id='gridExport'></div>");
// make dynamic clumn definations
var columnDefs = [];
var cols = colNames.split(",");
var colTitles = title.split(",");
for (var i = 0; i < cols.length; i++) {
columnDefs.push({ title: colTitles[i], field: cols[i] });
}
$("#main-content").find("#gridExport").empty().kendoGrid({
dataSource: {
data: ds,
pageSize: 20
},
toolbar: ["excel"],
excel: {
fileName: name + "_Export" + ".xlsx",
allPages: true
},
columns: columnDefs
});
$("#main-content").find("#gridExport").data("kendoGrid").saveAsExcel();
}
Comments
Post a Comment