Dmitry Nelepov
Dmitry Nelepov

Reputation: 7306

RestKit with CoreData and pagination

I have simple pagination scheme

http://api/users?page=1

gives users at page 1 after what i can ask next page like

http://api/users?page=2

and etc for next pages

But i have 2 problems:

  1. i can't ordering users in response to show as them came from server to me

[user1, user2, user3] but when i try fetch from database i can got [user2, user1, user3] for example.

I try use RestKit metadata property

@metadata.mapping.collectionIndex

But it's work each request independently. Happen next for

http://api/users?page=1 i got array

[user1, user2, user3] collectionIndex will be [1,2,3]. 

But then i ask next page and got array

[user4, user5, user6] collectionIndex also will be [1,2,3]

so in database

[user1, user4, user2, user5, user3, user6] 

it's not correct.

So first question: is it possible use collectionIndex for pagination requests without resets collectionIndex?

  1. Problem in new arrived data

I ask

http://api/users?page=1 and got 2 users

[user1, user2] in response

after i ask second page and got 2 users

[user3, user4] in response

so i ask again page=1 and now i got users [user01, user02]

and then go increment page index but, in page=2 i got [user1, user2] and in tableview in UI i see al records

[user01, user02, user1, user2, user3, user4] 

and then page ask nothing changes, so user can't understand is paging work?

To fix it i use FetchRequestBlock and then page=1 i erase all users - it's bad solution.

How to correct paginate data from server?

Upvotes: 1

Views: 230

Answers (1)

Wain
Wain

Reputation: 119031

  1. No, you need to add the page number into the store and add sort descriptors for page and index.
  2. I'd say your solution is ok. I'm not sure I'd use a fetch request block, but you need to mark all the items as invalid or delete them when you start paging from the beginning.

Upvotes: 2

Related Questions