Enabling pagination on a primary collection

To enable pagination on a primary collection:

  1. Perform one of these steps:
    • In the Windows client, open the form that you want to modify, then go into Design Mode.
    • In the web client, launch the Web Designer, then open the form that you want to modify.
  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 Form > Behavior section, specify this information:
    Initial Command
    Specify Refresh.
    Script Language
    Select Visual C#.
  4. Right-click on the form, then select Form Script.
  5. Add the form script for the page controls. See the sample form script.
  6. Add events for each button:
    Button Event
    Previous GotoPrevPage
    Go to page GotoPage
    Next GotoNextPage
  7. On the Form > Collections tab, select the Primary Collection.
  8. In the Options > Advanced Options section, specify 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. Reset IDO cache, if necessary.
  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
   }
}