Search code examples
actionscript-3apache-flexsortingarraycollectiondataprovider

Flex Dropdownlist dataprovider reset on refresh


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; 
    }

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.