Usually you get only the "page" from the database.
Say the request
select * from mytable where column1="a";
will give 1000 records. Then getting the page will look like (mysql):
select * from mytable where column1="a" limit 0, 10;
for page 1 (from 0 to 10), and page 2 will be restored as follows:
select * from mytable where column1="a" limit 10, 20;
etc. If the data is large (1000 records) but not huge (1000 000 records), you can also immediately provide the entire data set and use javascript on the page. This has the added benefit that sorting can be done on the client side.
source share