Comments (16)
Can you paste a log of the state metadata in your response body here?
from backbone-pageable.
This is on the last time _checkState() is fired
{
currentPage: 1
filterStatus: undefined
filterText: undefined
firstPage: 1
lastPage: 0
order: null
pageSize: 15
sortKey: null
totalPages: 0
totalRecords: 0
}
It fires three times when I do a get*Page
.
from backbone-pageable.
You don't have to return so many states in your response body, you just have to return totalRecords
, and everything else will be recalculated when necessary. Alternatively, you can set totalRecords
to null
instead of 0 to skip _checkState
.
from backbone-pageable.
Returning null
worked like a charm!
from backbone-pageable.
It seems that issue with processing 0 in totalRecords is about totalPages calculation:
totalPages = state.totalPages = ceil(totalRecords / pageSize)
Assuming that firstPage === 1 for empty response, should the totalPages become 1 also?
from backbone-pageable.
Why would an empty response indicate having > 0 number of pages?
from backbone-pageable.
Considering the following condition:
firstPage === 1 && (currentPage < firstPage || currentPage > totalPages)
The state has firstPage === 1, currentPage === 1 and firstPage === 1. Passing condition leads to RangeError throwing. So there are two approaches: keep all related state properties actual (being 0) in case of totalRecords === 0 or force totalPages = 1 in this case.
As for me, server API should response only with total_entries === 0 in case of empty collection (e.g. after filtration). So the question is: should it be treated as first and single page (totalPages === 1)? If not, then the only way is to respond with total_entries === null (which makes server API less consistent).
from backbone-pageable.
The better question is, under what circumstances would you ever reach that state by using the paginator's methods? Are you manually fiddling the state yourself?
from backbone-pageable.
Yes, I'm setting state.currentPage = 1. But before fetching the filtered results.
from backbone-pageable.
Would this work for you?
else if (firstPage === 1 && (currentPage < firstPage || currentPage > totalPages && totalPages > 0)) {
from backbone-pageable.
Also, which mode are you using?
from backbone-pageable.
I'm using the "server" mode and yes - this condition works. So the question is about which workaround to use - && totalPages > 0
or ceil(totalRecords / pageSize) || 1
. Your one assumes that state.totalPages really should stay 0. It seems that we are about some "domain" choice - is it correct to say that we have a page for empty collection or not?
from backbone-pageable.
Can you obtain a grain of salt from an empty jar? That's a contradiction. I'll commit a fix for this. Thanks for letting me know.
from backbone-pageable.
But a jar is not supposed to disappear due to lack of salt :) Anyway, thanks a lot.
from backbone-pageable.
What if ?
currentPage: 4
firstPage: 1
pageSize: 10
totalPages: 1
totalRecords: 5
I am getting same issue! Plz help!
from backbone-pageable.
How can you have a totalRecords of 5, a pageSize of 10 and be on page 4? Of course you get an error.
from backbone-pageable.
Related Issues (20)
- `totalRecords` must be a finite integer HOT 9
- Pageable breaks when cloning collection HOT 15
- A bit tedious to prepare two sets of meta for server mode and infinite mode HOT 10
- Infinite Scrolling, Parse Link Error HOT 12
- Little concern about getLastPage() in server mode HOT 2
- Returning to same point in infinite when going back HOT 1
- getPage doesn't set correctly currentPage in client mode HOT 1
- infinite collection / fullcollection is confusing HOT 14
- Relationship between parseLinks and queryParams in infinite mode HOT 1
- Suggestion: infinite mode reset method HOT 6
- Uncaught RangeError: `currentPage` must be firstPage <= currentPage >= totalPages if 0-based. Got 7. HOT 10
- Support for 'pagesInRange' which is currently supported in Paginator. HOT 3
- Problematic line in combination with uglifier... HOT 3
- Setting order to null in queryParams sends null=desc or null=asc to server HOT 3
- Removing all items on a page does not change the page HOT 1
- Switching automatically between modes (Infinite to server mode)
- Get Method for getting individual queryParams value
- Weird behaviour with pageable on filtering
- Paginating with getNextPage() without Backgrid client mode
- In client mode, collection add will trigger remove event. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-pageable.