FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

Paginator

v1.1.0 Public

This module builds help you build a pagination struct for API responses and custom data tables.

ColdBox settings

You can overwrite the defaults for your app. This configuration goes in /config/ColdBox.cfc in moduleSettings.cbpaginator like so:

		moduleSettings = {
			"cbpaginator" = {
				"defaults" = {
					"maxRows": 25,
					"maxRowsLimit" : 200
				}
			}
		}

Settings

Here is the complete settings that you get by default.

			settings = {
			"defaults" = {
				"maxRows": 25,
				"maxRowsLimit" = 200
			},
			"apiPagination" = {
				"maxRows": 15,
				"maxRowsLimit" = 200
			},
			"elasticSearch" = {
				"maxRows": 50,
				"maxRowsLimit" = 200
			},
			"customPagination" = {
				"maxRows": 5,
				"maxRowsLimit" = 100
			}
		};

Usage

This module provides two functions to build your pagination struct:

  1. generate( required totalRecords, page, maxRows ) -> returns the pagination struct according to the total records.

If page and maxRows parameters are not passed in, it will use the default values.

The response will look like the following:

			{
				"totalPages": 0,
				"maxRows": 25,
				"offset": 0,
				"page": 1,
				"totalRecords": 0
			}
  1. generateWithResults( required totalRecords, required results, page, maxRows, resultMap=false, resultsKeyName="results" )

This function returns the same pagination struct as the above along with the results

You can convert your results to be a result Map by changing the default value of resultsKeyName to true

In addition you can set a name for your results key by passing in the resultsKeyName value as a parameter. By default this key is called results

		{
			"pagination" = {
				"totalPages": 0,
				"maxRows": 25,
				"offset": 0,
				"page": 1,
				"totalRecords": 0
			},
			"results" = []
		}

Just drop into your modules folder or use the box cli to install

box install cbpaginator

VERSIONS

1.1.0

  • Renaming module
  • Updating settings
  • Making functions name less verbose

Here are all the versions for this package. Please note that you can leverage CommandBox package versioning to install any package you like. Please refer to our managing package version guide for more information.

Version Created Last Update Published By Stable Actions
Current
1.1.0 Aug 28 2019 12:16 PM Aug 28 2019 12:16 PM
Version History
1.0.0 Aug 27 2019 02:59 PM Aug 27 2019 02:59 PM

 

No collaborators yet.
 
  • Aug 27 2019 02:50 PM
  • Aug 28 2019 12:16 PM
  • 93
  • 0
  • 121