One of the coolest...umm...features...of Flex 2 is the ability to extend any class, including any of the core, or native Flex/Flash classes. This allows developers to easily add functionality to classes, or modify existing functionality.
One thing that struck me as rather odd (I am not sure why I think its odd) was that there was no easy way to paginate data in an ArrayCollection, and there is only one control/container, <mx:Repeater>, that has native properties, startingIndex and count, which allows easy pagination of data.
I know that Flex...umm...Lifecyle Data Services (LDS), can help with this (I am not sure exactly how), but there are time when you may have a large data set that you cannot bring into your app from LDS. As a result of needing this for a project, and wanting to learn about extending Flex classes, I came up with PagableArrayCollection.
I was impressed with how easy it was to understand the documentation on how to extend classes, as well as how to add/override methods and properties of classes. PagableArrayCollection adds the following to the native ArrayCollection:
- itemsPerPage:Number - [read/write] - the number of items to display per 'page'
- currentPage:Number [read/write] - the currently viewed 'page'
- pages:Number - [read] - The number of 'pages' based on size of dataset and itemsPerPage.
- pageUp() - Goes one 'page' up in dataset.
- pageDown() - Goes one page down in dataset.
Check out a demo here. Or you can download the .zip file below.
I would love any feedback, or suggestions.




13 comments
thanks again dude
One thing that'd be a neat example: bind the rows per page to the displayed rows in a datagrid, so that if its height changes, the pagination follows suit.
Thanx!
Anybody got some sparetime to do some performance tests....?
And I always had my doubts with using filterfunction internally, because how are you going to handle it when you got multiple filterfunctions, mean when you want to use one on you PagedArrayCollection?
great work - but if you could delete the addItem-Bug this thing will be terrfic cool. Is there any chance to do this