MoonStorm / trNgGrid

A feature rich Angular grid using standard HTML tables.
MIT License
252 stars 66 forks source link

Getting the currently displayed elements alone (respecting filtering, pagination and sorting) #139

Closed mathanpec closed 9 years ago

mathanpec commented 9 years ago

Say when we give 100 objects to the grid and the current page size is 5, Is there any provision to know those 5 objects? Same with filtering also, Is there any way to get the objects which is being displayed as result of filtering or sorting? I couldn't find anything in the documentation.

MoonStorm commented 9 years ago

For the time being, no. I believe it could be solved through angular events. Will think about it.

mathanpec commented 9 years ago

I have done it using alias in ng-repeat (variable in expression as alias_expression ) by modifying trNgGrid code . Will raise a pull request for that.

jdforsythe commented 9 years ago

@mathanpec can you give more information on how you achieved this? it's a critical feature to my application to export the filtered data to csv and also pass it to another view for a printable report.

mathanpec commented 9 years ago

@jdforsythe , In the current version of trNgGrid, currentDisplayItems are being computed as filteredItems. But they aren't just exposed to external scope. So you need to modify the code little bit to get it via external scope same like how you selectedItems is exposed.

mathanpec commented 9 years ago

@MoonStorm, I see that filteredItems is being computed internally. But they aren't exposed like selectedItem. Is there any specific reason for not exposing this ? Because I had modified the code little bit to expose this also as isolated scope and wanted to know whether it is right approach?

MoonStorm commented 9 years ago

@mathanpec Not a bad solution. The only concern I've got is that being exposed this way it allows for external logic to make changes to the list of displayed items. For the selected items it makes sense to have it that way.

MoonStorm commented 9 years ago

@mathanpec Actually, there is an additional concern. The filtered items you were mentioning are actually already formatted, have the field names mangled, plus they hold a "very well hidden" data item. They were not meant to be exposed.

The selected items are actual data items.

jdforsythe commented 9 years ago

The change I made was

648d647
<             scope.$emit('exportableItemsChanged', scope.filteredItems);

then in the controller:

$scope.$on('exportableItemsChanged', function(event, data) {
    $scope.exportableItems = angular.forEach(data, function(value) {
        this.push(value.$$_gridItem);
    });
});

That is very well hidden data item, I presume. It's useful, though because I run the original object through a parser and pass it to alasql.js and xlsx.js to export the filtered and ordered data as Excel and CSV files.

As for the OP question, it doesn't respect pagination.

MoonStorm commented 9 years ago

Found some time to think about it and decided to implement it via data binding, as @mathanpec suggested, but instead of exposing the displayed items, it'll provide the data items instead.

Please see the updated Grid Options section on the demo site for more details. The changes were pushed on the master branch.