register

caph.ui.listItemLoaderProvider. register

Registers new item loader.

(static) register(name, config) → {caph.ui.listItemLoaderProvider}

Parameters:
Name Type Description
name string

The item loader name.

config Object

The item loader configurations.

  • url: A string containing the URL to which the request is sent. This is mandatory.
  • method: The HTTP method to use for the request. Although you can use one of the all HTTP methods, recommend using 'GET' or 'JSONP'. Default value is 'JSONP'.
  • headers: Map of strings representing HTTP headers to send to the server. This is optional.
  • parameterNames: The item loader sends a request to the given URL with several parameters. These parameters are 'page', 'offset', 'count' and 'callback'. Because the item loader maintains internal data cache to fixed size. So these parameters are required. 'page' is the required page count. 'offset' is the start index of the required page. 'count' is the loading count per page. 'callback' is used for JSONP request. You can change the request parameter names to provide an object which consists of parameter name-replacement name string pairs.
  • loadingCount: The item loading count for each request. This value is calculated automatically according to the designated list's item view count per page. Although you can set this value to whatever you want, it's not recommended.
  • thresholdCount: The server request threshold count. When the designated list reaches as far as threshold count from both side of the item loader's internal data cache, the item loader sends a request to get the required data. This value is calculated automatically according to the designated list's item view count per page. Although you can set this value to whatever you want, it's not recommended.
  • getTotalCount: A function returns a total count using the response data for the request. This function receives two parameters. One is 'data' which represents a response data, another is 'status' which represents a response status code. You should return a total count as a number using these parameters. This is mandatory.
  • getItems: A function returns an array of the required items using the response data for the request. This function receives a 'data' parameter which represents a response data. Default function just returns the response data directly. If you need to parse the response data to make an array of the items, you should override default function to meet your requirements.
  • onBeforeLoad: A function which is called before sending a request. This function receives a parameter which represents item loader itself.
  • onAfterLoad: A function which is called after sending a request. This function receives two parameters. One is 'data' which represents a response data, another is 'status' which represents a response status code. This function can receive item loader itself as a third parameter.
Returns:
Type
caph.ui.listItemLoaderProvider
Example
angular.module('myApp', ['caph.ui']).config(['listItemLoaderProvider', function(listItemLoaderProvider) {
 	listItemLoaderProvider.register('loader1', {
 		url: '/someUrl',
 		parameterNames: {
 			offset: 'start'
 		},
 		getTotalCount: function(data, status) {
 			return data.totalCount;
 		},
 		getItems: function(data) {
 			return data.items;
 		}
 	});
 }]);