Question

I have couple of dropdownlist controls, that shares the same dataprovider(same reference).

I had overridden the set dataprovider method for a sort function.(code below). The issue is that, when I set this shared dataprovider to a new dropdownlist, all the existing dropdown contorls sharing the dataprvider gets unselected(loses its previously selected values).

    override public function set dataProvider(value:IList):void{
            if(value is ArrayCollection){
            var sort:Sort=new Sort();
            var sortField:SortField = new SortField();
            sortField.numeric=false;
            sort.fields=[sortField];

            ArrayCollection(value).sort=sort;
            ArrayCollection(value).refresh();
        }
        super.dataProvider=value; 
    }
Was it helpful?

Solution

There are a ton of isues sharing the dataProvider between components. We've run into this with a lot of clients using our AutoCompleteComboBox.

You can easily use the same source, but a different--separate--collection for each of your dataProviders.

var dataProvider1 :ArrayCollection = new ArrayCollection(someArray);
var dataProvider2 :ArrayCollection = new ArrayCollection(someArray);
var dataProvider3 :ArrayCollection = new ArrayCollection(someArray);

Each collection is just a wrapper around the base source. Sorting one will not affect any of the others, leaving your other ComboBoxes or DropDownLists untouched.

OTHER TIPS

I did no research on this, but there are two issues/ideas coming up:

  1. if you literally use the same reference to the same arraycollection, you do not need to sort this array more than once (and you actually do this by assigning the same arraycollection more than once)
  2. if it about only single-selection dropdowns, then there is a simple solution:

    var oldSelected : TypeOfItem = selectedItem as TypeOfItem;
    // do the sort (like in your code)
    super.dataProvider=value;
    selectedIndex = getItemIndex(oldSelected);
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top