This is a migrated thread and some comments may be shown as answers.

column metadata for Excel export

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Buchanan
Top achievements
Rank 1
Scott Buchanan asked on 06 Nov 2015, 02:39 PM

Greetings!  I have a set of grids to export to Excel.  I completed the first, with the help of your fine demo apps.

I have quite a bit of code for the OnExcelExport(e) event to set Excel column widths, cell colors, etc.  For example:

//Set column width and wrap text
if (colIndex == 0) {
    row.cells[colIndex].wrap = true;
    sheet.columns[colIndex].autoWidth = false;
    sheet.columns[colIndex].width = 63;
}
if (colIndex == 5 || colIndex == 6 || colIndex == 7) {
    row.cells[colIndex].wrap = true;
    sheet.columns[colIndex].autoWidth = false;
    sheet.columns[colIndex].width = 72;
}

My question is :Is there a way to store metadata in the column definition of the grid that I can read in OnExcelExport(e) so that I can create shared, generic functions to set the Excel attributes or must I code each grid like this (referencing column order, etc.)?  I tried stuffing attributes in the clientTemplate but this always seemed to affect my HTML grid...

Best,
Scott

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 09 Nov 2015, 03:04 PM

Hello Scott,

The metadata cannot be added to the columns through the fluent API (except as some data- HTML attributes), but you could add metadata to the columns definition on document.ready i.e. when the widget is initialized.
E.g.

$(function () {
    var grid = $("#grid").data("kendoGrid");
    grid.columns[0].myMetadata = { ... };
});

You could then access this custom data in the excelExport event and use it to customize the exported document. I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Scott Buchanan
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or