angular-data-grid / angular-data-grid.github.io

Light and flexible Data Grid for AngularJS applications.
http://angular-data-grid.github.io/demo/bootstrap/
112 stars 50 forks source link

Export grid data #54

Closed suvonkar closed 7 years ago

suvonkar commented 7 years ago

Hi @AndreyChayko ,

Can we get a export to Excel, PDF, CSV etc. feature from this grid data?

AlexanderZhukCoherent commented 7 years ago

@suvonkar I've added optional support for CSV file exports, see main Bootstrap demo for implementation details. Then CSV file can be converted to XLS or PDF format using Excel itself, if needed.

suvonkar commented 7 years ago

@AlexanderZhukCoherent , Thanks a lot for your help.

I would like to highlight something which is missing in the Demo. If you go to the CodePen then in the JS tab following section is missing.

    $scope.exportToCsv = function (currentData) {
        var exportData = [];
        currentData.forEach(function (item) {
            exportData.push({
                'Code': item.code,
                'Date Placed': $filter('date')(item.placed, 'shortDate'),
                'Status': item.statusDisplay,
                'Total': item.total.formattedValue
            });
        });
        JSONToCSVConvertor(exportData, 'Export', true);
    }

It will be helpful for others if you update the JS tab.

Thanks in advance.

AlexanderZhukCoherent commented 7 years ago

@suvonkar thanks for the reminder, done!

elizabeth commented 7 years ago

@AlexanderZhukCoherent Are you able to make it so that it's possible to generate the CSV file without the first few lines (the date and the report title) so that the file itself is purely just data?

AlexanderZhukCoherent commented 7 years ago

@erizabesu CSV export is just optional plug-in functionality, so it won't be a part of grid configuration etc. However, you can easily edit beginning of https://github.com/angular-data-grid/angular-data-grid.github.io/blob/master/src/js/vendors/JSONToCSVConvertor.js file to remove unwanted lines in the report.