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:

NameTypeArgumentDescription
pagesizeNumber

Size of the page, default is 1.

fetchsizeNumber

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.

fetchcallbackNumberoptional 

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.

fetchscopeNumberoptional 

Scope object in which to run the fetchCallback method in.

buffersizeNumberoptional 

Size of the page

Methods

addItems(items)

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

Parameters:

NameTypeDescription
itemsArray

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:

NameTypeDescription
indexNumber

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:

NameTypeArgumentDescription
indexNumber

Page index to fetch and return.

wrapBooleanoptional 

The data size is wrapped across multiple pages.

pagesizeNumberoptional 

The size the page needs to be.

quietBooleanoptional 

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:

NameTypeDescription
dataArray

Data that needs to be stored for paging.

totalNumber

Total data size.

removeItems(start, count)

Remove data from the dataset.

Parameters:

NameTypeDescription
startNumber

At which index to start removing the data.

countNumber

How many items to remove.

setFilter(fn)

Parameters:

NameTypeDescription
fnfunction

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:

NameTypeDescription
sizeNumber

The size that the page needs to be changed to.