locked
Efficient Paging and Sorting in WebMatrix RRS feed

Answers

  • User-821857111 posted

    The total number of records are obtained through a SELECT COUNT query:

    var sql = "SELECT COUNT (*) FROM Customers";
    count = db.QueryValue(sql);
    totalPages = count/pageSize;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 4:04 PM

All replies

  • User-821857111 posted

    I'm not sure what you are asking. The user will click on the paging links to navigate to the next page worth of records. Or are you asking about how to increase the default page size? You could do it by providing the user with a dropdown and pass the posted value to the pageSize variable.

    Tuesday, February 7, 2012 2:59 PM
  • User-1974948304 posted

    Thanks Mike, my question is, when you look at the Sample provided in the tutorial, the Page size is set to 10.
    If I understand correctly, the page size sets the Number of Pages to be shown to the number chosen, in this case 10. So 10 pages are initially displayed when the page loads.
    Now suppose I have more record that cannot fit into this  10 pages, meaning there are pages 11, 12, 13 etc.

    How will the user get to see these pages, beyond 10?  I was expecting  the paging link to say something like  .....Next 10 pages AFTER the initial 10 pages. That is, The user clicks on the last page in the Paging link (page 10 in the example), then the Following 10 pages are then displayed.  BUT I don't see that. Am I missing something?

    cheers,

    yousaid

    Tuesday, February 7, 2012 3:17 PM
  • User-821857111 posted

    Oh, I see. No - the pageSize represents the number of records that get displayed per page. totalPages represents the number of pages required to display all the records that meet the criteria in the SQL. It's calculated by dividing the total number of records by the records per page (pageSize).

    Tuesday, February 7, 2012 3:24 PM
  • User-1974948304 posted

    Thanks again Mike !!
    But how can one know before hand  the number of Pages required to to meet the criteria.
    Imagine for instance a Forum where  users are constantly adding records. How can one predict the this?
    Can you please point me to a sample.
    Using the downloaded sample, I can set the
    var totalPages = 20 (anticipating I will have that much records,) BUT what if I have more than that?
    I noticed you set the
    var totalpages = 0. Any reason why?
    cheers,
    yousaid

    Tuesday, February 7, 2012 3:42 PM
  • User-821857111 posted

    The total number of records are obtained through a SELECT COUNT query:

    var sql = "SELECT COUNT (*) FROM Customers";
    count = db.QueryValue(sql);
    totalPages = count/pageSize;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 4:04 PM
  • User439975351 posted

    Hi Guys, I know this is an old post but I'm making good use of the comments here and wondered what the best way to limit the number of pager links displayed.

    As with the forum scenario, lets say you have a page count of 100, the UI would become very cluttered if we displayed 100 pager links.

    I'm trying to get my head round the math invloved in displaying just 5 pager links but allowing the user to select +5 more or -5 less as appropriate.

    Any ideas, welcomed :)

    Thanks

    Wednesday, July 10, 2013 6:25 AM