jquery Easy UI Paging

Source: Internet
Author: User

In order to solve the problem of displaying data under large data volume, we need one effect: The user gets new data from the database each time the paging toolbar is manipulated, the server determines the data segment to be fetched according to the parameters passed back, and then queries the database for the data of the specified rows. Then pass it to the foreground by the DataGrid display.

First, set the initialization of the DataGrid

[JavaScript]View Plaincopyprint?
  1. $ (function () {
  2. $ (' #tableTrainee '). DataGrid (' Getpager '). Pagination ({
  3. Pagesize:10, //number of records displayed per page, by default
  4. PageList: [Ten, Three,], //You can set a list of the number of records per page
  5. Onselectpage: function (pagenumber, pageSize) {
  6. Searchtrainee (); //change is triggered each time the page is changed
  7. }
  8. });
  9. });

The Searchtrainee () method will be loaded once each time the page is updated.

Second, get the data and load

[JavaScript]View Plaincopyprint?
  1. function Searchtrainee () {
  2. Functionsearchtrainee () {
  3. var companycode =$ (' #hiddenCompanyCode '). Val ();
  4. var name = $ (' #txtName '). Val ();
  5. if (companycode== "") Companycode = "000";
  6. var dg =$ (' #tableTrainee ');
  7. var opts =dg.datagrid (' options ');
  8. var pager =dg.datagrid (' Getpager ');
  9. var _pagenumber =opts.pagenumber;
  10. var _pagesize =opts.pagesize;
  11. //Asynchronously gets data to JavaScript object, entry parameter is query condition and page number information
  12. $.post (' ajax/gettraineehandler.ashx ', {
  13. Name:name,
  14. Companycode:companycode,
  15. Pagenumber:_pagenumber,
  16. Pagesize:_pagesize
  17. }, function (data) {
  18. //Note that data from the database has a total column of record rows
  19. var total = json.parse (data). Rows[0].total;
  20. $ (' #tableTrainee '). DataGrid (' LoadData ', Json.parse (data));
  21. Pager.pagination ({
  22. //update pagination's navigation list parameters
  23. Total:total,//Total
  24. PageSize: _pagesize,//number of rows
  25. PageNumber: _pagenumber//pages
  26. });
  27. });
  28. }

The next task is to use the server to get the data for the database.

According to the above requirements, the database query statement can not use COUNT (*), select * Similar to the need for global search statements, because it is too time-consuming.

Online cattle people on the page search statements are very many posts, search methods are various, here I used the following:

[SQL]View Plaincopyprint?
    1. Select Top Page size * from ID
    2. Where ID not in
    3. (
    4. Select Top Page Size * (pages-1) ID from table ORDER by ID ASC
    5. )

The advantage of this statement is that you do not have to query all rows, the disadvantage is that the larger the page number, the less efficient the query. For example, it takes about 1 minutes to get 10 rows of data after 10 million rows in a single test.


Now the main problem is basically solved, but there are still many problems:

1. When you get the total number of data bars from the server, the Select COUNT (*) statement is used, which is similar to select *, where all the data needs to be searched, causing big data to become slow.

2. Not only can you improve query efficiency from query statements, you should add indexes to your database tables if you can, even better if you can add stored procedures.


2013.12.30 Supplement

When querying the database, you can also use the following statement

[SQL]View Plaincopyprint?
  1. SELECT TOP Page Size *
  2. From table1
  3. WHERE ID >
  4. (
  5. SELECT ISNULL (MAX (ID), 0)
  6. from
  7. (
  8. SELECT TOP Page Size * (pages-1) ID from table1 ORDER by ID
  9. ) A
  10. )
  11. ORDER by ID

By comparison, this statement is more efficient than using the not-in statement above, but still cannot avoid the fact that the page increase can lead to poor efficiency, and it still takes more than 1 minutes to get 10 rows of data after 10 million rows.

To get the total number of pages in the lower right corner of the DataGrid, it is unavoidable to use the Count statement, which will appear the short board of the query statement, helpless ~ ~

If you get the total number of rows without a condition, you can use the following statement

SELECT ROWS from sysindexes WHERE ID = object_id (' TableName ') and indid = 1

Note that it gets not the exact value, but the total number of database table rows that are updated by the server over time.

jquery Easy UI Paging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.