Número límite de lista flexible de elementos

Is it possible to define a property to limit the number of elements which will appear in a mx:List ? I've read about setting the property rowCount, but I don't see any effect. Can a filter be applied to accomplish this? My intention was to avoid removing the items from the list/array collection, but simply "hide" them. Can this be done?

preguntado el 09 de marzo de 12 a las 14:03

2 Respuestas

You can "hide" items from display in a List-based class, without modifying your underlying source data, by using a Collection class, such as an ArrayCollection, and filtering the data.

Lee esto docs on Collection filtering.

Citar:

You use a filter function to limit the data view in the collection to a subset of the source data object. The function must take a single Object parameter, which corresponds to a collection item, and must return a Boolean value specifying whether to include the item in the view. As with sorting, when you specify or change the filter function, you must call the refresh() method on the collection to show the filtered results. To limit a collection view of an array of strings to contain only strings starting with M, for example, use the following filter function:

public function stateFilterFunc(item:Object):Boolean
{
    return item >= "M" && item < "N";
}

respondido 09 mar '12, 14:03

Him thanks for the comment. However, I want to filter items based on their positions. In a certain view I want to show the first 20, and the other view I want to show all of them. Can I filter based on this? - Rui

@Rui I don't know what "Filter based on their positions" means. If you can define it; you can probably code it. Are you using the same dataProvider for two separate lists? - jeffryhouser

I'm already filtering items by date. On one state, I want my list to present the first 20 items, on other state I want to show all of them. - Rui

You can use originalCollection.getItemIndex(item) < 20 as your condition in the filter function. Also to note rowCount I believe is a way to set the height on the component based on how many rows you want visible before having to scroll. - Shaunhusain

A different option is to use a new arraycollection and get your limited items from your big arraycollection :

//get first 10 elements
myArrayCollection = new ArrayCollection( myBigArrayCollection.toArray().slice(0,9) );

if you want to work with pagers, you could hold a counter where you keep track of what page the user is on, and get the next elements from you big array collection. example:

//this is just a (very) simple example
//page = integer (counter) for knowing which page the user is on
page = 0;
page_low = page*10;
page_high = page_low + 9;
myArrayCollection = new ArrayCollection( myBigArrayCollection.toArray().slice(page_low,page_high) );

(still using a filter is a more elegant solution)

respondido 13 mar '12, 22:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.