I'll give a conceptual answer since i don't know anything about your server. Basically on the client you have a page
variable which initializes to 0. On your server you have a chunk
variable which is set to 10. Each time you need to load data, you increment page
and send an ajax request with the page
as a parameter.
Your server will then query the database for rows page * chunk
through (page * chunk)+chunk-1)
. This requires that you select all rows, give each row an index, and then retrieve the proper chunk. Notice the -1
for [inclusive,exclusive] chunks.
Example:
page = 0;
chunk start index = page * chunk = 0
chunk end index = page * chunk + chunk - 1 = 9
Retrieve rows 0-9 from database.
page = 1;
chunk start index = page * chunk = 10
chunk end index = page * chunk + chunk - 1 = 19
Retrieve rows 10-19 from database.
page = 2;
chunk start index = page * chunk = 20
chunk end index = page * chunk + chunk - 1 = 29
Retrieve rows 20-29 from database.
You can tweek the chunk
variable to how ever many records you want per call.