开发者

invalidateList() not working for AdvancedDataGrid when fired by custom subclass

I want to persist the AdvancedDataGrid column order for the user if they move them around and close the window or log out. I have code (see below) that works when I place the code in a grid parent container - eg, a title window. I'd like to generalise the functionality by placing the code in an AdvancedDatagrid subclass rather than each grid container so that all my grids have access to a single location when saving/loading their choices. My approach is to store the datafield names and grid name in an array and save/read to/from the shared object. and update the column order based on that order. The invaldation fails when I use the code in the Advanced Datagrid subclass but works fine in the grid parent. Anyone got any ideas?. ive been banging my head against this for 2 days :(

private function loadSettings(name:String = "custom"):void { var gridName:String = this.stripUIDNumbers(this.uid); var temp:Array = new Array;

        this.wsColOrder = SharedObject.getLocal(sharedObjectName);
        if (wsColOrder.size > 0)
        {
            for each (var item:* in wsColOrder.data)
            {
                if (item is Array && item.in开发者_如何学CdexOf(gridName) != -1) // check for the current grid
                {
                    for each (var saveColDataField:String in item)
                    {
                        for each (var existingCol:AdvancedDataGridColumn in this._columns)
                        {
                            if (existingCol.dataField == saveColDataField)
                            {
                                temp.push(existingCol);
                            }
                        }
                    }
                    this._columns.splice(0); // clean out the existing colum array
                    this._columns =  temp  //  assign persisted  col order
                    this.invalidateList(); // update the grid
                }
            }
        }
        else
        {
           // saveSettings("default");
        }


At first glance, I'd ask why you're using the _columns var. Using the 'columns' getter/setter will guarantee that you're using the invalidation process and the correct flags are being set and reset in your inherited AdvancedDatagrid..... 'tis the first thing I'd change. (also, the splice(0) line is unneeded when you're setting columns array on the next line).

WELL, that's the second thing I'd change... I'd first make sure that your local sharedObjects get typed, but that's a personal preference for my own code readability. Google "flash.net.registerClassAlias" or do something with a ValueObject class such that you can store the dataField order so you do not have to do a "for each *".

Hope that helps at least a little. Best of luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜