Enabling pagination on a primary collection

You can enable pagination, or control of the number of records to be displayed, for the records of a primary collection.

  1. Open the form that you want to configure or modify in the designer (Web Designer in the web client, Design Mode in the Windows client.
  2. Add these page control components:
    • Page number field, for example: Page 1 out of 28
    • Current page field
    • Previous button
    • Go to page button
    • Next button
  3. In the Behavior section of the Form properties sheet, provide this information:
    Initial Command
    Select Refresh.
    Script Language
    Select Visual C#.
  4. Right-click on the form, and then select Form Script.
  5. Add the form script for the page controls.
    See the sample form script.
  6. Add these events for each button:
    Button Event
    Previous GotoPrevPage
    Go to page GotoPage
    Next GotoNextPage
  7. On the Collections tab of the Form properties sheet, select the primary collection.
  8. In the Advanced Options section of the Options group, provide this information:
    Record Cap Override/Page Size
    Specify the record cap or the page size of the selected collection.
    Enable Paging
    Select True.
  9. Click Save.
  10. Refresh the IDO metadata cache.
  11. Test the form.
Example of form script code for the page control components:
using System;
using Mongoose.IDO.Protocol;
using Mongoose.Scripting;
using Mongoose.Core.Common;
using System.Diagnostics;

namespace Mongoose.FormScripts
{
   public class TestSinglePage : FormScript
   {
      /// <summary>
      /// Triggered when Go to Page button (Primary Collection) is clicked
      /// </summary>
      public void GotoCurrentPage()
      {
         int pageNum = ThisForm.Variables( "CurrentPageVar" ).GetValue<int>();
         ThisForm.PrimaryIDOCollection.GotoPage( pageNum );
         DisplayCurrentPage( pageNum );
      }

      /// <summary>
      /// Triggered when Go to Next button (Primary Collection) is clicked
      /// </summary>
      public void GotoNextPage()
      {
         int pageNum = ThisForm.Variables( "CurrentPageVar" ).GetValue<int>();
         int maxNumPage = ThisForm.PrimaryIDOCollection.GetNumPages();
         int nextPage = pageNum >= maxNumPage ? maxNumPage : pageNum + 1;

         // Do not proceed if requesting the same page number
         if ( pageNum == nextPage )
            return;

         ThisForm.PrimaryIDOCollection.GotoPage( nextPage );
         DisplayCurrentPage( nextPage );
      }

      /// <summary>
      /// Triggered when Previous button (Primary Collection) is clicked
      /// </summary>
      public void GotoPreviousPage()
      {
         int pageNum = ThisForm.Variables( "CurrentPageVar" ).GetValue<int>();
         int prevPage = pageNum <= 1 ? 1 : pageNum - 1;

         // Do not proceed if requesting the same page number
         if ( pageNum == prevPage )
            return;

         ThisForm.PrimaryIDOCollection.GotoPage( prevPage );
         DisplayCurrentPage( prevPage );
      }

      /// <summary>
      /// Fills up Paging Info, and the Current page of Primary Collection
      /// </summary>
      /// <param name="pageNum"></param>
      public void DisplayCurrentPage( int pageNum )
      {
         ThisForm.Components["CurrentPageEdit"].Value = string.Format( "Page {0} out of {1}", pageNum.ToString(), ThisForm.PrimaryIDOCollection.GetNumPages().ToString() );
         ThisForm.Variables( "CurrentPageVar" ).SetValue( pageNum.ToString() );
      }

      #region SubCollection

      /// <summary>
      /// Triggered when Go to Page button (SubCollection) is clicked
      /// </summary>
      public void GotoCurrentPageSub()
      {
         int pageNum = ThisForm.Variables( "CurrentPageSubVar" ).GetValue<int>();
         ThisForm.PrimaryIDOCollection.GetSubCollection( "Properties", 0 ).GotoPage( pageNum );
         DisplayCurrentPageSub( pageNum );
      }

      /// <summary>
      /// Triggered when Next button (SubCollection) is clicked
      /// </summary>
      public void GotoNextPageSub()
      {
         int pageNum = ThisForm.Variables( "CurrentPageSubVar" ).GetValue<int>();
         int maxNumPage = ThisForm.PrimaryIDOCollection.GetSubCollection( "Properties", 0 ).GetNumPages();
         int nextPage = pageNum >= maxNumPage ? maxNumPage : pageNum + 1;
         ThisForm.PrimaryIDOCollection.GetSubCollection( "Properties", 0 ).GotoPage( nextPage );
         DisplayCurrentPageSub( nextPage );
      }

      /// <summary>
      /// Triggered when Prev button (SubCollection) is clicked
      /// </summary>
      public void GotoPreviousPageSub()
      {
         int pageNum = ThisForm.Variables( "CurrentPageSubVar" ).GetValue<int>();
         int prevPage = pageNum <= 1 ? 1 : pageNum - 1;
         ThisForm.PrimaryIDOCollection.GetSubCollection( "Properties", 0 ).GotoPage( prevPage );
         DisplayCurrentPageSub( prevPage );
      }

      /// <summary>
      /// Fills up Paging Info, and the Current page of Subcollection
      /// </summary>
      public void DisplayCurrentPageSub( int pageNum )
      {
         ThisForm.Components["CurrentPageEditSub"].Value = string.Format( "Page {0} out of {1}",
                                                               pageNum.ToString(),
                                                               ThisForm.PrimaryIDOCollection.GetSubCollection( "Properties", 0 ).GetNumPages().ToString() );
         ThisForm.Components["PageNumberEditSub"].Value = pageNum.ToString();
      }
      #endregion
   }
}