MAF.utility.Pager

The pager is a storage class for data. Grids can communicate with them by default.

new MAF.utility.Pager(pagesize, fetchsize, fetchcallback, fetchscope, buffersize)

Parameters:

Name Type Argument Description
pagesize Number

Size of the page, default is 1.

fetchsize Number

Fetch size, the number of items in the data set fetched at one time. The default fetch size is 48. You can fetch several pages at ones from the server.

fetchcallback Number optional 

A fetch method callback you provide for the next data set of items. This is the event delegate that knows how to fetch data in your server’s unique way.

fetchscope Number optional 

Scope object in which to run the fetchCallback method in.

buffersize Number optional 

Size of the page

Methods

addItems(items)

Takes a Array of items and adds them to the dataset.

Parameters:

Name Type Description
items Array

These will be added to the dataset.

getDataSize() → {Number}

Retrieves the total size of the dataset.

Returns:

Total size of the dataset.

getFetchSize() → {Number}

Retrieves the value indicating how large a fetch for more data will be.

Returns:

The size of a fetch in a slice. Default is 48.

getItem(index) → {Mixed}

Parameters:

Name Type Description
index Number

retrieves item at this index.

Returns:

Item at the specified index.

getItems() → {Array}

Retrieve all data that is stored.

Returns:

An Array containing the data thats stored, if a filter is set the data returned will be filtered.

getItemsSize() → {Number}

Returns:

The size of the dataset. This will reflect its size filtered.

getNumPages() → {Number}

Returns:

The number of pages in the dataset.

getPage(index, wrap, pagesize, quiet) → {MAF.utility.PagerStorageClass}

Retrieves a page size nr of items.

Parameters:

Name Type Argument Description
index Number

Page index to fetch and return.

wrap Boolean optional 

The data size is wrapped across multiple pages.

pagesize Number optional 

The size the page needs to be.

quiet Boolean optional 

Notify subscribers or not. Default it notifies.

Returns:

A page of items as a storageClass.

getPageSize() → {Number}

Returns:

The size of the page that the pager is configured to.

initItems(data, total)

Initialize pager with data, you can call this multiple times. This will reset the pager.

Parameters:

Name Type Description
data Array

Data that needs to be stored for paging.

total Number

Total data size.

removeItems(start, count)

Remove data from the dataset.

Parameters:

Name Type Description
start Number

At which index to start removing the data.

count Number

How many items to remove.

setFilter(fn)

Parameters:

Name Type Description
fn function

Callback method in which you can define which values to filter.

Example

var pager = new MAF.utility.Pager(2, 6);
pager.initItems([1,2,3,4,5,6], 6);
pager.setFilter(function (value, key) {
   if (value > 2)
      return value;
   }
});
pager.getItems(); // Returns [3,4,5,6]

setPageSize(size)

Parameters:

Name Type Description
size Number

The size that the page needs to be changed to.