jQuery pagination and size immense
I want to using of the jQuery pagination
,The problem is in this that, for this must all 开发者_如何学运维data in the tabale(database)
are select
.
Now for example if we have a table database of 10,000 rows
, for pagination with jQuery size
it is immense
(select all to page).
What is the solution of the use pagination jQuery
with the low size data
in page?
NOTE: i not want use of plugin
With respect
Regardless of whether you use a plugin, or jQuery for that matter, you should be paginating these on the server with your DB query as opposed to selecting everythign and then paginating the data. You would do this by using LIMIT
and OFFSET
in the query.
First make a qount query to determine how man records there are:
SELECT COUNT(*) AS nb_records FROM your_table;
You now have all the records available for the query. And you can figure out how many total pages you have based on how many records you want per page something like this in php:
$pages = ceil($nb_records/$max_per_page);
So now that you have this figured out you can use a page number parameter passed from the request to determine the beginning offset of the records for that page and query for the data. For example if you pass in page 2 and there are 100 total records, and you want 10 per page you can calculate the offset for the start of page 2 is 20 ($max_per_page*$page = $offset
) making your query:
SELECT * FROM your_table LIMIT 20 OFFSET 40;
So if we are talking ajax on the frontend you would make a request to the page performing the query with the page number something like this:
$.ajax({
url: 'page/that/makes/query.php'
type: 'get',
data: {"page": 1} // or whatever page}
success: function(data){}
});
This would then return either the complete html markup for the "page" of records or a data object (JSON, XML) containing the details of each record which you would use to build the html.
精彩评论