Filtering not working properly with paging.
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?
The grid can't filter things it cannot see.
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)
Three possible options:
- 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
- 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)
- Use the existing "externalFiltering" api to build your own filtering (which is sort of like option 1, but perhaps not as clean)
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.
I don't think sorting does work with pagination.
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.
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?
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'}
]
};
};
}]);
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.
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?
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...
- map visible rows into another array, then slice the page off
- set all rows except the current page invisible
Willing to give either a try.
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.
FWIW I have this merged into my branch and it seems to be working fine for me.
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.
The PR was merged, you might need to use the latest unstable release. I know it is in there.
@brianchance cool! :)
Can you confirm that this is now working so that we can close?
This seems to work now thank you :)
Excellent, thanks.