angular-ui / ui-grid

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

export functionality should be able to export sorted data #1972

Closed edenchen123 closed 9 years ago

edenchen123 commented 9 years ago

export functionality should be able to export sorted data

PaulL1 commented 9 years ago

I think it does, if you export visible rows. The sorted rows are held in the visible rows cache. If you export all, then it uses grid.rows, which is not sorted. If you export visible, then it uses grid.visibleRows, which is sorted. I think this makes sense. If you haven't filtered, then visibleRows and allRows are the same thing, so you could just export visible rows. If you have filtered, then the sort would only apply to the filtered rows - we can't easily export sorted for rows that aren't visible.

csharpengineer commented 9 years ago

Yes, but what about when data is paged? I have paged data and I would like to export all rows using the current sort. I have tried temporarily changing the page size to fit all rows, calling export on visible rows and then setting the page size back, however even with a notification to grid that the page size has changed, the exporter still exports just the current page.

PaulL1 commented 9 years ago

I believe there is now an option to get all paged data before export, it does require handling a callback.

csharpengineer commented 9 years ago

Ah, thanks. Is this exporterAllDataPromise?

PaulL1 commented 9 years ago

Sounds right.

ruhaise commented 6 years ago

I'm using angular ui-grid for large set's of data, now i'm able to export the filtered result's from all paginations,when i apply the sort functionality along with it, it works on the view but not on the imported file, that is the user again needs to sort it after the download using excel(which isn't convenient).

NB: Extra dependencies i have used 1.xlsx.js 2.underscore.js 3.alasql.js

function exportData() {
            $scope.exportDatalist = _.filter($scope.gridApi.grid.rows, (o) => {
               return o.visible;
            });
            var entities = _.map($scope.exportDatalist, 'entity');
            alasql.promise('SELECT * INTO XLSX("Log_Details.xlsx",{headers:true}) FROM ?', [entities]);
        }
nisharamj commented 6 years ago

@csharpengineer @PaulL1 Could you please show here the sample code, can be used to resolve this problem?