Ask and ye shall receive ... we solved this exact problem about a month ago ...
-------------------------------------------------------------------------
// Save grid settings to shared object
public function saveGridSettings():void {
var name:String = lineItemGrid.name;
var gWidth:int = lineItemGrid.width;
var cols:Array = new Array();
var savedLastSort:String = lastSort;
var savedReversed:Boolean = reversed;
for (var i:int = 0; i <
lineItemGrid.columns.length; i++) {
cols[i] = lineItemGrid.columns[i];
}
// Write grid data to shared object
lineItemGridSO =
SharedObject.getLocal("gridData", "/");
lineItemGridSO.data.name = name;
lineItemGridSO.data.gridWidth = gWidth;
lineItemGridSO.data.lastSort = savedLastSort;
lineItemGridSO.data.reversed = savedReversed;
lineItemGridSO.data.gridCols = new Array();
lineItemGridSO.data.gridCols = cols;
lineItemGridSO.flush();
}
// Get grid settings from shared object
public function getGridSettings():void {
lineItemGridSO =
SharedObject.getLocal("gridData", "/");
if (lineItemGridSO.data.name != undefined) {
lastSort =
lineItemGridSO.data.lastSort;
var newCols:Array = new Array();
for (var i:int = 0; i <
lineItemGridSO.data.gridCols.length; i++) {
for (var j:int = 0; j <
lineItemGrid.columns.length; j++) {
if
(lineItemGrid.columns[j].dataField ==
lineItemGridSO.data.gridCols[i].dataField) {
var
newCol:DataGridColumn = DataGridColumn(lineItemGrid.columns.splice(int(j),
1)[0]);
newCol.width =
lineItemGridSO.data.gridCols[i].width;
newCols.push(newCol);
}
}
}
newCols.concat(lineItemGrid.columns);
lineItemGrid.columns = newCols;
}
}
---- "Ian M. Jones" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm trying to set up a simple way to save a user's DataGrid column setup
> to a local SharedObject, and then retrieve those settings when they next
> run the application.
>
> Saving them seems to have been pretty simple:
>
> public function savePreferences():void {
> var prefs:SharedObject = SharedObject.getLocal("Preferences");
> var defaultColumns:Array = myDataGrid.columns;
> prefs.data.defaultColumns = defaultColumns;
> prefs.flush();
> }
>
> That works, I can see the objects in the Preferences.sol file, but I
> haven't found a way of setting the grid's columns after reading it back
> in.
>
> I've tried reading back into an array and then setting the columns
> property to the array.
> I've tried iterating through the array with a for each casting the results
> to a DataGridColumn, appending to an ArrayCollection and then finally
> setting the DataGrid's columns to the ArrayCollection.toArray, that didn't
> get very far.
> I've tried binding the DataGrid's columns property to an Array, and then
> setting that array to the prefs.data.defaultColumns.
>
> Nothing seems to work, the app generally seems to hang at the point I try
> to set the columns property.
>
> Is there a kind soul that can point me in the right direction?
>
> Thanks,
> --
> Ian M. Jones
> ________________________________________
> IMiJ Software
> http://www.imijsoft.com
> http://www.ianmjones.net (blog)
>