IgniteUI / ignite-ui

Ignite UI for jQuery by Infragistics

Home Page:https://bit.ly/2kuu1fT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve how igGrid exports to Excel. Maintain raw data values while applying proper formatting on Excel cells / columns

merjoha opened this issue · comments

On the "columns" array option of the igGrid, there are two existing properties for formatting cell data in the rendered grid... "format" and "formatter". Both work well for formatting data rendered in the grid itself, but they provide very little help when the data is exported to Excel using the &.ig.GridExcelExporter. For example, using format="currency" on a column with a number data type will yield the expected results in the grid, but when the data is exported to Excel, the raw number is sent to Excel (unformatted). Also, defining a "formatter" function yields the expected results in the grid, but the data is exported to Excel as the formatted string value, which is nice visually but aggravating if you wanted to do computations in the Excel spreadsheet with the resulting data.

My suggestion is to add a string property on igGrid column objects in columns array called "excelFormat". This would be used on columns with number and date data types primarily. Acceptable values of this excelFormat property would be valid Excel cell format codes. Then, when a grid is exported to Excel using the $.ig.GridExcelExporter, any number or date column with the excelExport property set would have it's raw number or date value in the underlying data source exported to Excel. The value provided for the excelFormat would then be applied to the cell in Excel. This way, you retain the actual data values along with the formatting you want on those values in Excel. Ideally (for performance reasons on large data sources), the formatting of the cells would take place in the exportEnding event at the column level instead of on a cell-by-cell basis in the cellExporting event.