Giter VIP home page Giter VIP logo

Comments (16)

wyuenho avatar wyuenho commented on July 18, 2024

Can you paste a log of the state metadata in your response body here?

from backbone-pageable.

jbraithwaite avatar jbraithwaite commented on July 18, 2024

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. Screen Shot 2013-02-09 at 2 25 35 AM

from backbone-pageable.

wyuenho avatar wyuenho commented on July 18, 2024

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.

jbraithwaite avatar jbraithwaite commented on July 18, 2024

Returning null worked like a charm!

from backbone-pageable.

oleksmarkh avatar oleksmarkh commented on July 18, 2024

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.

wyuenho avatar wyuenho commented on July 18, 2024

Why would an empty response indicate having > 0 number of pages?

from backbone-pageable.

oleksmarkh avatar oleksmarkh commented on July 18, 2024

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.

wyuenho avatar wyuenho commented on July 18, 2024

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.

oleksmarkh avatar oleksmarkh commented on July 18, 2024

Yes, I'm setting state.currentPage = 1. But before fetching the filtered results.

from backbone-pageable.

wyuenho avatar wyuenho commented on July 18, 2024

Would this work for you?

else if (firstPage === 1 && (currentPage < firstPage || currentPage > totalPages && totalPages > 0)) {

from backbone-pageable.

wyuenho avatar wyuenho commented on July 18, 2024

Also, which mode are you using?

from backbone-pageable.

oleksmarkh avatar oleksmarkh commented on July 18, 2024

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.

wyuenho avatar wyuenho commented on July 18, 2024

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.

oleksmarkh avatar oleksmarkh commented on July 18, 2024

But a jar is not supposed to disappear due to lack of salt :) Anyway, thanks a lot.

from backbone-pageable.

Ratikant01 avatar Ratikant01 commented on July 18, 2024

What if ?
currentPage: 4
firstPage: 1
pageSize: 10
totalPages: 1
totalRecords: 5

I am getting same issue! Plz help!

from backbone-pageable.

wyuenho avatar wyuenho commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.