ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Filtering not working properly with paging.

Open conanak99 opened this issue 12 years ago • 22 comments

I use the lastest ui-grid unstable version. For example, I have a table of 500 tries, each page contains 50 entries.

When I try to filter a property, I excepted it to filter all 500 entries, and paging the filtered result. But it only filter the 50 entries of the current page. Is this a bug? Can I configure somewhere to make it works as I excepted?

conanak99 avatar Nov 24 '14 07:11 conanak99

The grid can't filter things it cannot see.

PaulL1 avatar Nov 24 '14 07:11 PaulL1

Thanks. So, is there anyway for me to get the behavior I expected? (The grid will filter all 500 entries and paging the filtered result)

conanak99 avatar Nov 24 '14 08:11 conanak99

Three possible options:

  1. Do a pull request to extend the pagination API to also push filter events to the user, which would then be applied outside the grid
  2. Do a pull request to modify the pagination API so that it knows about the full data set, and deals with the pagination inside (this would probably not work well with server pagination, but could work with client pagination)
  3. Use the existing "externalFiltering" api to build your own filtering (which is sort of like option 1, but perhaps not as clean)

PaulL1 avatar Nov 24 '14 08:11 PaulL1

I have a question, how come sorting works with pagination but filtering does not? I am new to ui-grid and admit that I have not delved deeply into the logic, so please forgive me if this is a dumb question.

Thanks.

bamab avatar Nov 24 '14 23:11 bamab

I don't think sorting does work with pagination.

PaulL1 avatar Nov 24 '14 23:11 PaulL1

It does with this unstable version: ui-grid - v3.0.0-rc.16-0885e50 - 2014-11-14. I have it working in my local environment. I can sort from A - Z / 0 - 9 but filter only what's on the page.

bamab avatar Nov 24 '14 23:11 bamab

I suspect it's only sorting the data in the page(s) that it can see, not the full data set. How sure are you that sorting is working?

PaulL1 avatar Nov 24 '14 23:11 PaulL1

Positive. I'm working on a Plunker now. I will share it once I am finished. But here is all I am doing in the js:

'use strict';

angular.module('myApp.view1', ['ngRoute'])

    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/view1', {
            templateUrl: 'view1/view1.html',
            controller: 'View1Ctrl'
        });
    }])

    .controller('View1Ctrl', ['$scope', function($scope) {
        $scope.init = function() {
        $scope.people= [];
        for (var i=0; i<50; i++) {
            $scope.people.push({
                first: chance.first(),
                last: chance.last(),
                address: chance.address(),
                city: chance.city(),
                state: chance.state(),
                zip: chance.zip(),
                phone: chance.phone(),
                date: chance.date()
            });
        }

        $scope.peopleGridOptions = {
            data: 'people',
            enableFiltering: true,
            pagingPageSizes: [5, 10, 20],
            pagingPageSize: 5,
            columnDefs: [
                         {field: 'first', displayName: 'First Name'},
                         {field: 'last', displayName: 'Last Name'},
                         {field: 'address', displayName: 'Address'},
                         {field: 'city', displayName: 'City'},
                         {field: 'state', displayName: 'State', width: 85},
                         {field: 'zip', displayName: 'Zip', width: 75},
                         {field: 'phone', displayName: 'Phone'},
                         {field: 'date', displayName: 'Date', cellFilter: 'date'}
            ]
        };

    };

}]);

bamab avatar Nov 25 '14 00:11 bamab

Plunker

bamab avatar Nov 25 '14 01:11 bamab

OK, paging, not pagination. Better that we hurry up and merge those two plugins. Paging seems to know about all the data, but just show a subset, whereas pagination only knows about the subset. So...for paging it should be plausible to filter the full set, but I gather that it hasn't been built that way.

PaulL1 avatar Nov 25 '14 01:11 PaulL1

Both paging (client side) and pagination work the same, by slicing the rows passed to registerRowsProcessor. Same plunker with pagination and it does not filter either.

Does the filter use a rowsProcessor that runs after?

brianchance avatar Nov 25 '14 22:11 brianchance

I finally had a chance to look into this. The filter is setting the row.visible = false, then both paging and pagination just take the slice of rows.

I see a couple choices...

  1. map visible rows into another array, then slice the page off
  2. set all rows except the current page invisible

Willing to give either a try.

brianchance avatar Dec 10 '14 17:12 brianchance

Thanks if this works please merge. I don't think filtering only the current page when multiple pages are available is ever going to make sense in any scenario. However I can see server side paging/filtering needing support as well.

wgorder avatar Dec 10 '14 20:12 wgorder

FWIW I have this merged into my branch and it seems to be working fine for me.

wgorder avatar Dec 12 '14 14:12 wgorder

Got the same problem, have 10k+ items in the data source, and i would like the filter to filter on the datasource and not care about paging. the paging plugin should just page the filtered results which might be 200 rows out of the 10k, where each page is 50 items would make 4 total pages.

furier avatar Jan 09 '15 23:01 furier

The PR was merged, you might need to use the latest unstable release. I know it is in there.

brianchance avatar Jan 09 '15 23:01 brianchance

@brianchance cool! :)

furier avatar Jan 09 '15 23:01 furier

Can you confirm that this is now working so that we can close?

PaulL1 avatar Jan 14 '15 21:01 PaulL1

This seems to work now thank you :)

furier avatar Jan 14 '15 21:01 furier

Excellent, thanks.

PaulL1 avatar Jan 14 '15 21:01 PaulL1