angular-ui / ui-grid

UI Grid: an Angular Data Grid
http://ui-grid.info
MIT License
5.39k stars 2.47k forks source link

Broken formatting in both exported CSV and Excel files since v4.6.1 #6887

Closed dmitry-borzov closed 3 years ago

dmitry-borzov commented 5 years ago

Plunkr: http://plnkr.co/edit/7yFTvr1z35AzmlZjzDUF?p=preview

Expected result (as it worked until v4.4.6): 8.99 -13.09 51.45 -1,128.65

Actual result in CSV: null9

NAME?

null51 -null1,129

Actual result in Excel: null9 -null13 null51 -null1,129

It looks like the bug was introduced in the following commit: https://github.com/angular-ui/ui-grid/commit/3207b292445617d5477e5aee5d23d160b3c8bf62

The code in the commit changes filter parameters from return $filter('currency')(value, ""); to return $filter('currency')(value, null, null); It gives wrong output.

johnoscott commented 5 years ago

anyone know if this is getting fixed ?

johnoscott commented 5 years ago

workaround is to override the broken default implementation by setting this in your grid options

grid.options = {
    // return raw call value without cellFilters being applied          
    exporterFieldCallback: function ( grid, row, col, value ) {
        return value;
   },...
}
Neonchen commented 4 years ago

Extending the workaround from @johnoscott you can just apply all cellFilters by yourself:

exporterFieldCallback: function ( grid, row, col, value ) {
        // example for a more advanced filter
        if(col.cellFilter === "date:\'dd.MM.yyyy\'") { 
            value = $filter('date')(value, 'dd.MM.yyyy')

        //every common filter like 'currency'
        } else if ( col.cellFilter !== "") {
           value = $filter(col.cellFilter)(value)
        }
        //all cols without filter just return the value
        return value;
}
Cornchips007 commented 4 years ago

How are people not getting their build broken by the parameters not being found? I can replace grid with this.myGrid but row, col and value I'm just not sure about.

I'm using typescript but can type them as any.

image

Answer: Just add types to the parameters. e.g. (grid: uiGrid.IGridApi, row: uiGrid.IGridRow, col: uiGrid.IGridColumn, input: any)

mportuga commented 3 years ago

should be fixed by https://github.com/angular-ui/ui-grid/pull/7154/files