0
I have a advanceddatagrid that has around 15 columns. Some are string,
some are numbers. I have shown 4 columns below.
The number columns have formatting done for zero precision and 2
digits precision.  The itemRenderer is just to show Blue Color if the
number is +ve and Red Color if the number is -ve.
It looks something like below

<mx:columns>
<mx:AdvancedDataGridColumn dataField="Name" textAlign"left"/>
<mx:AdvancedDataGridColumn dataField="Time" textAlign="right"/>
<mx:AdvancedDataGridColumn dataField="Score" textAlign="right"  formatter="{zeroPrecisionFormatter}" sortable="true"   itemRenderer="ColorRenderer" />
<mx:AdvancedDataGridColumn dataField="Average" textAlign="right" headerWordWrap="true" formatter="{twoPrecisionFormatter}" itemRenderer="ColorRenderer" />

...

I am trying to save the users setting of column order  when he closes
the application and reload with the same order when the user opens the
applications. I am using SharedObjects and below is the code.

for(var i:int=0; i< adgrid.columns.length;i++){
     var columnObject:Object = new Object(); 
     columnObject.columnDataField = adgrid.columns[i].dataField as String;
     columnObject.columnHeader =adgrid.columns[i].headerText as String;
     columnObject.width = adgrid.columns[i].width;
     columnArray.push(columnObject);
 }

and then I save the columnArray to SharedObject.

I retrive them using the below code

 for(var i:int=0;i<columnArray.length;i++){  
    adgrid.columns[i].dataField =columnArray[i].columnDataField;
    adgrid.columns[i].headerText =columnArray[i].columnHeader;
    adgrid.columns[i].width = columnArray[i].width;
    }

How can I save and reload the Formatter and ItemRenderer data .
I am having trouble saving the formatter and itemrenderer and
reloading it again.


I would really appreciate if you can shown the code. 
How can I reshuffle the columns but can preserve all the properties of it to though  sharedobject and recover it again. 
4

1 回答 1

1
            private function loadLayout(name:String="custom"):void {
            var storedLayoutData:SharedObject; 
            storedLayoutData = SharedObject.getLocal("layouts");
            if (storedLayoutData.data["pocketBankDG_"+name]) {
                var columns:Array = new Array();
                var index:int = 0;
                for each (var column:Object in storedLayoutData.data["pocketBankDG_"+name]["columns"]) {
                    for ( var key:String in column) {
                        var propClass:Class = getDefinitionByName(column[key].propClassName) as Class;
                            adgOperations.columns[index][key] = column[key].propValue as propClass;
                    }
                    index++
                }
            } else {
                saveLayout("default");
                openSettingsWindow();
            }
        }

        private function saveLayout(name:String="custom"):void {
            var storedLayoutData:SharedObject; 
            storedLayoutData = SharedObject.getLocal("layouts");
            if (!storedLayoutData.data["pocketBankDG"]) storedLayoutData.data["pocketBankDG_"+name] = new Object();             
            var columns:Array = new Array();
            for each(var column:AdvancedDataGridColumn in adgOperations.columns) {
                var describeType:XML = flash.utils.describeType(column);
                var accessoriesList:XMLList = describeType..accessor;
                var data:Object = new Object;
                for each(var accessor:XML in accessoriesList) {
                    if (accessor.@access=="readwrite") {
                        var propClassName:String = getQualifiedClassName(column[accessor.@name]);
                        var propValue:* = column[accessor.@name];
                        if (propClassName=="String" || propClassName=="int" || propClassName=="Boolean" || 
                            propClassName=="Number" || propClassName=="uint") {
                            data[accessor.@name] = {}
                            data[accessor.@name].propClassName = propClassName;
                            data[accessor.@name].propValue = propValue;

                        }
                    }
                }               
                columns.push(data);
            }

            storedLayoutData.data["pocketBankDG_"+name]["columns"] = columns;
            storedLayoutData.flush();
        }
于 2010-09-30T11:48:14.790 回答