RKCY
RKCY

Reputation: 4135

ItemRenderer vs Repeater in Flex

Any one of you know about the difference between ItemRenderer and Repeater. Both are behaving the same almost. Any difference is there?

Upvotes: 1

Views: 2272

Answers (2)

RIAstar
RIAstar

Reputation: 11912

The biggest difference: Repeater has been deprecated discontinued. It exists as an mx component in Flex 3 only and there is no Spark equivalent in Flex 4. It is encouraged that you use DataGroup+ItemRenderer instead. The main reason for this is very clearly explained in @www.Flextras.com's answer.

Besides that, IMO for anything but the most basic usage Repeater can be a serious pain. Its paradigm is completely different from all the other Flex components, whereas a DataGroup+ItemRenderer approach is very much in line with the Flex component set.

Bottom line: do not use Repeater. There's nothing you can do with Repeater that you can't do with DataGroup+ItemRenderer. (Unless perhaps you're stuck with Flex 3 for some reason. See Amy's comments for more on this.)

Upvotes: 2

JeffryHouser
JeffryHouser

Reputation: 39408

Any one of you know about the difference between ItemRenderer and Repeater. Both are behaving the same almost. Any difference is there?

I'm not sure how they could be behaving the same, but without seeing your code, it is hard to judge. I will try to explain the difference; or rather; what each one is.

Under the hood An itemRenderer is a ClassFactory. A factory is a design pattern for a class that creates other classes. In the context of Flex, itemRenderers are used in list based classes, such as a DataGrid or List. The list based classes accept a dataProvider and only render the elements seen on the screen. As you scroll through the list, each component generated by the itemRenderer is reused. I call this renderer recycling. So, it is important that you implement your itemRenderer to respond to the dataChange event so it is always properly rendering the data it is supposed to represent. More info on itemRenderer components.

A Repeater is like a loop in MXML. Using a repeater does not provide any of the "renderer" benefits that a list based class does. Everything created inside your loop is renderered at once.

So, let's say you have a dataProvider with 100 images. You have space to show 10 of them on screen. With a list based class, flex will render and load 10 images; changing what is loaded as you scroll through the list. With a Repeater Flex will render and load all 100 at once even though not all of them are on the screen.

Upvotes: 4

Related Questions