保存在DataGrid的状态:可见列,列宽和顺序 [英] save state of a dataGrid: visible columns, columns width and order
问题描述
我要远程保存FLEX3的DataGrid的(对数据库)的状态(可见列,列宽和顺序)。
I want to save remotely (on a database) the state (visible columns, columns width and order) of a Flex3 DataGrid.
有关宽度和可见性,我可以简单地将它们保存通过访问各列的属性..丑,但有可能.. 但对于订单?我一定要动态创建DataGrid的??
For width and visibility I can simply save them by accessing each column attribute.. ugly but possible.. But for the order? Do I have to create the dataGrid dynamically??
任何想法是AP preciated 谢谢
Any idea is appreciated thanks
推荐答案
在我来说,我已经被头名保存的命令(我做你的DataGrid中始终具有相同的列头名的假设)。
In my case I have saved the order by header name (I'm making an assumption that your DataGrid always has the same columns and header names).
for (var n:Number = 0; n< datagrid.columns.length; n++)
{
var thiscol:DataGridColumn = DataGridColumn(datagrid.columns[n]);
colArray.addItem(thiscol.headerText);
}
然后,我可以通过检索列标题的顺序列表,并根据需要交换的数据网格列的位置恢复列的顺序。
Then I can restore the column order by retrieving the ordered list of column headers, and swapping the position of columns in the datagrid as required.
for (var n:Number = 0; n < colArray.length; n++)
{
moveColumnTo(String(colArray.getItemAt(n)), n);
}
我已经定义了一个函数moveColumnTo()来执行切换。
I have defined a function moveColumnTo() to perform the switch.
private function moveColumnTo(columnName:String, columnIndex:Number):void
{
// Find current column position
var i:Number = -1;
for (var n:Number = 0; n < datagrid.columns.length; n++)
{
if (DataGridColumn(datagrid.columns[n]).headerText == columnName)
{
i = n;
break;
}
}
if (i == -1 || i == columnIndex) return; // Don't shift column
this.mx_internal::shiftColumns(i, columnIndex); // Shift column to required position
}
这篇关于保存在DataGrid的状态:可见列,列宽和顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!