FLEX: I lose current datagrid selection if I sort differently the items of its dataProvider.

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2010-04-16T16:02:08Z Indexed on 2010/04/16 16:13 UTC
Read the original article Hit count: 515

Filed under:

hi,

when I sort differently my datagrid items, I lose the current selection.

This is the code. I'm using savedSelectedItems array to restore the selectedItems but it doesn't work. How can I save the current selection.

     private function sortItems(option:String):void {

            //save selectedItems
            savedSelectedItems = tagsList.selectedItems;


            if (option == "tag") sort.fields = [new SortField("tag",true)];
            if (option == "popularity") sort.fields = [new SortField("popularity",true)];

            fullTagsDataModel.tagsData.sort = sort;
            fullTagsDataModel.tagsData.refresh();

            tagsList.selectedItems = savedSelectedItems;

        }

...


<!-- tags list -->
    <dataGrid:CheckBoxList id="tagsList"
                        width="100%"
                        height="100%"
                        initialize="tagsList.dataProvider=fullTagsDataModel.tagsData"
                        labelField="tag"
                        itemRenderer="com.CheckBoxListAndDataGrid.CheckBoxRenderer" 
                        allowMultipleSelection="true"
                        click="savedSelectedItems = tagsList.selectedItems"
                        />

© Stack Overflow or respective owner

Related posts about flex