Solved

PAgination by grouping pages

Posted on 2004-09-09
5
258 Views
Last Modified: 2010-04-17
Hi I am looking for solution for Pagination by grouping. Currently I have a form from which the user can select the  number of rows or records he wants to see. This information is passed to another form where the total numbers of records is got and then divided by the number of rows passed to get the total number of pages and is shown as strvariable  For ex if the number of records is 1000 and number of rows passed is 25 there will be 40 pages with links to all and next and previous links. But I want the pages to be shown in groups of 10. If there are more than ten pages the first 10 will be shown as 1,2,3,4,5,6,7,8,9,10..>>>Next 10 and so on. The links to previous should be active. Can someone help?

Thanks
0
Comment
Question by:PNKJ
5 Comments
 
LVL 32

Expert Comment

by:ldbkutty
Comment Utility
so, which language are you using ?
0
 

Author Comment

by:PNKJ
Comment Utility
vbscript
0
 
LVL 2

Accepted Solution

by:
Freak4VB earned 500 total points
Comment Utility
Hi There !

Am posting a code that contains an exact implementation of this logic you are trying to build in. Had to write this sometime back for an application. The code is not too complicated (though trust me the algo is !!).
C_NEXTLINK and C_... are all constants declared in a class called OtherConstants so u needn't worry abt them, just replace them wit >> or << or watever !

OtherConstants.C_MAXPAGES = 10 that is the maximum number of pages u want the system to display at once. Keep on changing it to whatever value u want and everythin would still work !!

 Dim lsDelimiter As String
    Dim liLoop As Integer
    Dim lsHyperLink As String
    Dim liPageCount As Integer = 1
    Dim lsPrevLink As String = ""
    Dim lsNextLink As String = ""
    Dim liPrevPage As Integer = 0
    Dim liNextPage As Integer = 0
    Dim liQuotent As Integer = 0
    Dim liRemainder As Integer = 0
    Dim liTemp As Integer = 0
    Dim liMaxPages As Integer = OtherConstants.C_MAXPAGES

    Try

      'General Rules
      '1. Previous link would come only if current page is > MaxNumberofAllowedPages and the user is not viewing a page in the first batch of pages
      '2. Next link would come if the total number of pages is >MaxNumberofAllowedPages and totalnumberofpages - currentpage > MaxNumberofAllowedPages

      lsDelimiter = "<img src='images/gifDotedLine.gif' hspace='3' align='absbottom'>"


      'find if the Prev link is to be rendered or not and make the string if it is to be rendered
      If miCurrentPage > liMaxPages Then
        'Find the previous page that the Previous link should point to

        liQuotent = Math.DivRem(miCurrentPage, liMaxPages, liRemainder)
        If liRemainder = 0 Then
          liPrevPage = miCurrentPage - liMaxPages
        Else
          liPrevPage = miCurrentPage - liRemainder
        End If

        'Render previous link
        lsHyperLink = "&nbsp;<a href = ""javascript:togglePage('" & liPrevPage & "')"""
        lsHyperLink = lsHyperLink & ">" & OtherConstants.C_PREVLINK & "</a>&nbsp;"
        lsPrevLink = lsHyperLink
      End If

      liQuotent = 0
      liRemainder = 0
      'Find if the Next LInk is required and calculate and render the string if it is required

      If miTotalPages > liMaxPages Then
        liQuotent = Math.DivRem(miTotalPages, liMaxPages, liRemainder)
        If liRemainder = 0 Then
          liTemp = (liQuotent - 1) * liMaxPages + 1
        Else
          liTemp = (liQuotent * liMaxPages) + 1
        End If

        If miCurrentPage < liTemp Then
          'Next link required, calculate and generate the string
          liNextPage = liPrevPage + liMaxPages + 1
          lsHyperLink = "&nbsp;<a href = ""javascript:togglePage('" & liNextPage & "')"""
          lsHyperLink = lsHyperLink & ">" & OtherConstants.C_NEXTLINK & "</a>"
          lsNextLink = lsHyperLink
        End If

      End If
      liTemp = 0
      'Now we will calculate the boundaries of our For Loop
      'Lower bound is always liPrevPage+1
      'Upper bound will be lower of liPrevPage+maxpages and miTotalPages


      liTemp = Math.Min(liPrevPage + liMaxPages, miTotalPages)
      For liLoop = liPrevPage + 1 To liTemp
        If liLoop <> miCurrentPage Then
          lsHyperLink = "<a href = ""javascript:togglePage('" & liLoop & "')"""
          lsHyperLink = lsHyperLink & ">" & liLoop & "</a>"

        Else
          lsHyperLink = liLoop
        End If
        If liLoop <> liTemp Then
          lsHyperLink = lsHyperLink & lsDelimiter
        End If
        msPageNum = msPageNum & lsHyperLink
      Next

      'Append the prev next srtings
      If lsNextLink.Trim <> "" Then
        lsNextLink = lsDelimiter & lsNextLink
      End If
      If lsPrevLink <> "" Then
        lsPrevLink = lsPrevLink & lsDelimiter
      End If
      msPageNum = "Page: " & lsPrevLink & msPageNum & lsNextLink

    Catch ex As Exception
      Throw ex
    End Try
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now