如何在Adobe flex中重新加载Grid后修复Gridview

时间:2011-02-02 06:09:44

标签: flash flex flex3 adobe

我搜索了很多,但找不到确切的方法来做到这一点...... 如果你看一遍这个页面,你会更好地理解。 freescale。请在IE中打开它。这是我的情景...

点击power Actuation下leftnav中的om Analog & Power Management。你会得到结果表及以上,我有一个显示不同过滤条件的容器。现在找到一个可过滤的标题(带有过滤器标题的匹配标题名称),它在屏幕右侧折叠。然后选择过滤器练习的值,按其过滤。

now here my problem arises

重新加载结果后,表视图返回到它的起始位置,这会给最终用户带来关于结果的混淆。

所以我的问题是如何阻止我的表格视图回到它的起点?
我想我的结果应该是这样的..
Value is chosen for filtering, filtering starts, the reloaded values appear in the same screen position, as before the value was chosen

我想过viewStack但是无法想办法怎么做? 任何建议或解决方案将高度赞赏!!!!!
提前感谢您花费宝贵的时间来阅读我的问题。

1 个答案:

答案 0 :(得分:2)

单击过滤器后,将datagrid的'horizo​​ntalScrollPosition'存储在变量中。然后在表中加载数据后,重新设置horizo​​ntalscrollposition。

我在下面提供了一个示例。在此示例中,有一个数据网格和一个按钮。点击按钮数据加载后,我通过在加载数据后设置'horizo​​ntalScrollPosition'值来保持滚动位置。

<mx:DataGrid id="dataGridsfgh"
             left="15"
             top="41"
             dataProvider="{employeeList}"
             width="100%"
             horizontalScrollPolicy="on">
    <mx:columns>
        <mx:DataGridColumn headerText="First Name"
                           dataField="firstname"
                           width="40"/>
        <mx:DataGridColumn headerText="Last Name"
                           dataField="lastname"
                           width="40"/>
        <mx:DataGridColumn headerText="Designation"
                           dataField="designation"
                           width="40"/>
        <mx:DataGridColumn headerText="Contact # (Desk)"
                           dataField="deskphone"
                           width="40"/>
        <mx:DataGridColumn headerText="Contact # (Mobile)"
                           dataField="mobilephone"
                           width="40"/>
        <mx:DataGridColumn headerText="Contact # (Home)"
                           dataField="resphone"
                           width="40"/>
        <mx:DataGridColumn headerText="Address"
                           dataField="address1"
                           width="40"/>
        <mx:DataGridColumn headerText="Address"
                           dataField="address2"
                           width="40"/>
        <mx:DataGridColumn headerText="State"
                           dataField="state"
                           width="40"/>
        <mx:DataGridColumn headerText="Zip"
                           dataField="zip"
                           width="40"/>
        <mx:DataGridColumn headerText="Country"
                           dataField="country"
                           width="40"/>
    </mx:columns>
</mx:DataGrid>
<mx:Button x="36"
           y="228"
           label="Save position"
           click="addData();"/>

Actionscript代码:

    private function addData():void
        {
            var temp:int=dataGridsfgh.horizontalScrollPosition;
            var employeeObj:Object=new Object();
            employeeObj.firstname="John";
            employeeObj.lastname="Henry";
            employeeObj.designation="Developer";
            employeeObj.deskphone="XXX-XXX-XXXX";
            employeeObj.mobilephone="XXX-XXX-XXXX";
            employeeObj.resphone="XXX-XXX-XXXX";
            employeeObj.address1="#XXX Seawall Blvd";
            employeeObj.address2="Apt # XXX";
            employeeObj.location="Maui";
            employeeObj.state="Hawaii";
            employeeObj.zip="XXXXX";
            employeeObj.country="U.S";
            employeeList.addItem(employeeObj);
            dataGridsfgh.dataProvider=employeeList;
            dataGridsfgh.invalidateDisplayList();
            dataGridsfgh.horizontalScrollPosition=temp;
        }

希望这有帮助!