TPagedList class
TPagedList implements a list with paging functionality.
TPagedList works in one of two modes, managed paging or customized paging, specified by CustomPaging.
- Managed paging (CustomPaging=false) :
the list is assumed to contain all data and it will manage which page
of data are available to user.
- Customized paging (CustomPaging=true) :
the list is assumed to contain only one page of data. An OnFetchData
event will be raised if the list changes to a different page.
Developers can attach a handler to the event and supply the needed data.
The event handler can be written as follows,
- public function fetchData($sender,$param)
- {
- $offset=$param->Offset; // beginning index of the data needed
- $limit=$param->Limit; // maximum number of data items needed
- // get data according to the above two parameters
- $param->Data=$data;
- }
Data in TPagedList can be accessed like an integer-indexed array and can be traversed using foreach. For example,
- $count=$list->Count;
- for($index=0;$index<$count;++$index)
- echo $list[$index];
- foreach($list as $index=>$item) // traverse each item in the list
The PageSize property specifies the number of items in each page. To access different page of data in the list, set CurrentPageIndex or call nextPage(), previousPage(), or gotoPage(). The total number of pages can be obtained by PageCount.
Method Summary |
integer
|
|
integer
|
|
boolean
|
|
boolean
|
|
boolean
|
|
Iterator
|
|
integer
|
|
integer
|
|
integer
|
|
integer|boolean
|
Changes to a page with the specified page index.
|
integer
|
|
mixed
|
Returns the item at the specified offset.
|
integer|boolean
|
Switches to the next page.
|
boolean
|
Returns whether there is an item at the specified offset.
|
mixed
|
Returns the item at the specified offset.
|
void
|
Raises OnFetchData event.
|
void
|
Raises OnPageIndexChanged event.
|
integer|boolean
|
Switches to the previous page.
|
void
|
|
void
|
|
void
|
|
void
|
|
array
|
|
Method Details |
getCount
public integer getCount |
() |
Output |
integer
| the number of items in current page |
Exception |
|
getCurrentPageIndex
public integer getCurrentPageIndex |
() |
Output |
integer
| current page index. Defaults to 0. |
Exception |
|
getCustomPaging
public boolean getCustomPaging |
() |
Output |
boolean
| whether to use custom paging. Defaults to false. |
Exception |
|
getIsFirstPage
public boolean getIsFirstPage |
() |
Output |
boolean
| whether the current page is the first page |
Exception |
|
getIsLastPage
public boolean getIsLastPage |
() |
Output |
boolean
| whether the current page is the last page |
Exception |
|
getIterator
public Iterator getIterator |
() |
Output |
Iterator
| iterator |
Exception |
|
getPageCount
public integer getPageCount |
() |
Output |
integer
| number of pages, -1 if under custom paging mode and VirtualCount is not set. |
Exception |
|
getPageSize
public integer getPageSize |
() |
Output |
integer
| number of items in each page. Defaults to 10. |
Exception |
|
getVirtualCount
public integer getVirtualCount |
() |
Output |
integer
| user-assigned number of items in data source. Defaults to 0. |
Exception |
|
gotoPage
public integer|boolean gotoPage |
(integer $pageIndex ) |
Changes to a page with the specified page index.
Input |
integer | $pageIndex | page index |
Output |
integer|boolean
| the new page index, false if page index is out of range. |
Exception |
|
indexOf
public integer indexOf |
(mixed $item ) |
Input |
mixed | $item | the item |
Output |
integer
| the index of the item in the list (0 based), -1 if not found. |
Exception |
|
itemAt
public mixed itemAt |
(integer $index ) |
Returns the item at the specified offset.
This method is exactly the same as offsetGet.
Input |
integer | $index | the index of the item |
Output |
mixed
| the item at the index |
Exception |
throws | TInvalidDataValueException if the index is out of the range |
|
nextPage
public integer|boolean nextPage |
() |
Switches to the next page.
Output |
integer|boolean
| the new page index, false if next page is not available. |
Exception |
|
offsetExists
public boolean offsetExists |
(integer $offset ) |
Returns whether there is an item at the specified offset.
This method is required by the interface ArrayAccess.
Input |
integer | $offset | the offset to check on |
Output |
Exception |
|
offsetGet
public mixed offsetGet |
(integer $offset ) |
Returns the item at the specified offset.
This method is required by the interface ArrayAccess.
Input |
integer | $offset | the offset to retrieve item. |
Output |
mixed
| the item at the offset |
Exception |
throws | TInvalidDataValueException if the offset is invalid |
|
onFetchData
Raises OnFetchData event.
This event is raised each time when the list changes to a different page and needs the new page of data. This event can only be raised when CustomPaging is true.
|
onPageIndexChanged
Raises OnPageIndexChanged event.
This event is raised each time when the list changes to a different page.
|
previousPage
public integer|boolean previousPage |
() |
Switches to the previous page.
Output |
integer|boolean
| the new page index, false if previous page is not available. |
Exception |
|
setCurrentPageIndex
public void setCurrentPageIndex |
(integer $value ) |
Input |
integer | $value | current page index |
Output |
Exception |
throws | TInvalidDataValueException if the page index is out of range |
|
setCustomPaging
public void setCustomPaging |
(boolean $value ) |
Input |
boolean | $value | whether to allow custom paging |
Output |
Exception |
|
setPageSize
public void setPageSize |
(integer $value ) |
Input |
integer | $value | number of items in each page |
Output |
Exception |
|
setVirtualCount
public void setVirtualCount |
(integer $value ) |
Input |
integer | $value | user-assigned number of items in data source |
Output |
Exception |
|
toArray
Output |
array
| the list of items in array |
Exception |
|