Pagination Code
Pagination Code
Hello friends,
Today, I am sharing a pagination snippet with you. ( http://www.webnersolutions.com/ )
=============================================================================
Function name : calculateTotalPageNumber
-----------------------------------------------------------------------------------------------------------------------------------------------
list calculateTotalPageNumber(int total_record, int display_per_record)
{
if (input.total_record <= input.display_per_record)
{
calculate_record = true;
}
else
{
total_record_in_decimal = (input.total_record / display_per_record);
total_record_in_string = "'" + total_record_in_decimal + "'";
if (total_record_in_string.contains("."))
{
total_record_ = total_record_in_string.getPrefix(".");
total_record_in_ = (total_record_).replaceAll("'","",false);
total_record_in_int = total_record_in_.toLong();
}
else
{
total_record_in_ = (total_record_in_string).replaceAll("'","",false);
total_record_in_int = total_record_in_.toLong();
}
total_record_modules = (input.total_record % display_per_record);
total_record_modules = total_record_modules.toLong();
calculate_record = false;
}
if (calculate_record)
{
pageCount = 1;
}
else
{
if (total_record_modules > 0)
{
pageCount = (total_record_in_int + 1);
}
else
{
pageCount = total_record_in_int;
}
}
initial_list = {1};
final_record = thisapp.makePageNumberList(1, pageCount, initial_list);
return final_record;
}
=======================================================================================
Function Name : makePageNumberList
---------------------------------------------------------------------------------------------------------------------------------------------------------------
list makePageNumberList(int counter, int pageNumber, list:int mylist)
{
if (input.counter < input.pageNumber)
{
input.counter = (input.counter + 1);
input.mylist.add(input.counter);
thisapp.makePageNumberList(input.counter, input.pageNumber, input.mylist);
}
return input.mylist;
}
===================================================================================
Example 1 :
//Set Variable :
total_record=150
display_per_record = 50
//Calling Function
thisapp.calculateTotalPageNumber(total_record, display_per_record);
//Return
[1, 2, 3]
***************************************************************************************************************************
Example 2 :
//Set Variable :
total_record=150
display_per_record = 10
//Calling Function
thisapp.calculateTotalPageNumber(total_record, display_per_record);
//Return
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
************************************************************************************************************************