Comments (14)
Yep. I will add a demo to Backgrid.js today, but at the mean time you can take a look at the README and the QUnit tests. If you are working with Rails, you can just extend PageableCollection with a url, and everything else should just work like a plain Backbone.Collection with some extra methods.
from backbone-pageable.
Read from the source that the state are checked before making the request.
So if I don't have/know the "totalRecords" when I instantiate a new collection (server mode), does it mean that I need to do it manually inside the parse(), like calculating the "totalPages", "lastPage" and stuffs.
I need these state data to render the pagination UI (may probably try the Backgrid later but i want to use it separately by now).
Please correct me if i'm wrong.
Thanks
from backbone-pageable.
Generally you should bootstrap your server mode PageableCollection
in your server side template, in which you should have a count. If your web page is a static page, you can still omit totalRecords
when you instantiate a server mode PageableCollection
. states
is only checked when totalRecords
, pageSize
, currentPage
and firstPage
are all non-null, which is often not the case during instantiation. To grab the first page and update a server mode PageableCollection
state after instantiation, issue a fetch
to yield the server side states according to the queryParams
mapping in the JSON response. No overriding parse
is required.
from backbone-pageable.
Thanks for your promply response. For some reasons, bootstrapping a collection is not feasible in my case.
And I did call fetch() on collection to get the first page.
Here's is my config:
state: {
firstPage: 1,
pageSize: Config.pageSize
},
queryParams: {
currentPage: 'page',
pageSize: 'pageSize',
totalPages: null,
totalRecords: null
},
parse: function(response) {
this.state.totalRecords = response.total;
this.state.totalPages = Math.ceil(this.state.totalRecords / this.state.pageSize);
this.state.lastPage = this.state.totalPages;
return response.data;
}
Do I have to customize the response from the server-side
Please help.
from backbone-pageable.
totalPages
and lastPage
will be calculated automatically, you only need to provide totalRecords
. If you've nulled out queryParams.totalPages
and queryParams.totalRecords
, you can still provide a response like this, you just need to manually get total
from response[0].total
to set state.totalRecords
.
from backbone-pageable.
So you mean either I alter the server response for the fetch request using format like [{ pagination state }, [{}, {} ...]]
or I have to set "totalRecords" (and those depends on it) myself, am I correct?
One more thing, I notice Pageable's Collection.create() no longer trigger "add/request/sync" events when i call . Is it on purpose or any workarounds for that?
from backbone-pageable.
You need to provide a response format like [{ pagination state }, [{}, {} ...]]
and override parse
to set state.totelRecords
manually since you've nulled out queryParams.totalRecords
.
I didn't do anything with the create
method and the Backbone.Collection test case for it passes. It should still trigger the appropriate events.
from backbone-pageable.
That's strange. I read the source that you didnt touch this part but when i switch back to plain old backbone collection, I can see those events(add/request/sync) propagates, which is missing if using Pageable.
Please let me know should you need me to provide more information.
Thanks for your help along the way.
from backbone-pageable.
File a separate bug report if you believe backbone-pageable is at fault. Please provide a jsfiddle or jsbin link when you do so.
from backbone-pageable.
Sorry, it's my fault.
I passed the plain old BB collection as dependency instead of the Pageable.
It works fine. Thanks for your help and work.
from backbone-pageable.
Thanks for the demos. Just wanted to let you know that the Infinite demo seems not to be working now.
from backbone-pageable.
@alanrubin It seems to work fine here. Github's API has a 60 req/hr rate limit on public access. Did you run out of quota?
from backbone-pageable.
The API request returns the correct results. Have you tried in FF ? I have tried with Safari and it works, so probably a FF issue.
from backbone-pageable.
WTF. Looks like a Firefox bug 608735. Thanks for reporting.
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.