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.
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
}
}