In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).
在Flex中,我使用以下代码来允许在DataGrid中进行排序(数据是分页和排序的服务器端)。
private function headerReleaseHandler(event:DataGridEvent):void { var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]); if(this.count>0) { if(this.query.SortField == column.dataField) { this.query.SortAscending = !this.query.SortAscending; } else { this.query.SortField = column.dataField; this.query.SortAscending = true; } this.fill(); } event.preventDefault(); }
This works perfectly, except that the arrows that indicate sorting isn't shown. How can I accomplish that?
除了没有显示指示排序的箭头之外,这完全有效。我怎么能做到这一点?
Thanks! /Niels
3 个解决方案
#1
5
There is an example here if this is what you are looking for: http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/
这里有一个例子,如果这是你正在寻找的:http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-具有到点击一列/
It looks like you need to refresh the collection used by your dataprovider.
看起来您需要刷新数据提供者使用的集合。
#2
1
I have encountered the same problem and the only solution I found was to override the DataGrid and create a custom one. Here is the class:
我遇到了同样的问题,我发现的唯一解决方案是覆盖DataGrid并创建一个自定义的。这是班级:
public class DataGridCustomSort extends DataGrid
{
public function DataGridCustomSort()
{
super();
addEventListener(DataGridEvent.HEADER_RELEASE,
headerReleaseHandlerCustomSort,
false, EventPriority.DEFAULT_HANDLER);
}
public function headerReleaseHandlerCustomSort(event:DataGridEvent):void {
mx_internal::sortIndex = event.columnIndex;
if (mx_internal::sortDirection == null || mx_internal::sortDirection == "DESC")
mx_internal::sortDirection = "ASC";
else
mx_internal::sortDirection = "DESC";
placeSortArrow();
}
}
You have to specifically call the placeSortArrow() method when you get the HEADER_RELEASE event and set the column index and direction information.
获取HEADER_RELEASE事件并设置列索引和方向信息时,必须专门调用placeSortArrow()方法。
#3
0
in the above code what does "this" refer to is it the datagrid because I am confused by this.query.SortField , I am assuming 'this' and "query' are your own custom objects. and why are you checking for count. what count is that.
在上面的代码中,“this”引用的是datagrid,因为我对this.query.SortField感到困惑,我假设'this'和“query”是你自己的自定义对象。为什么要检查count。那是什么意思。
Regards -Mohan
#1
5
There is an example here if this is what you are looking for: http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/
这里有一个例子,如果这是你正在寻找的:http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-具有到点击一列/
It looks like you need to refresh the collection used by your dataprovider.
看起来您需要刷新数据提供者使用的集合。
#2
1
I have encountered the same problem and the only solution I found was to override the DataGrid and create a custom one. Here is the class:
我遇到了同样的问题,我发现的唯一解决方案是覆盖DataGrid并创建一个自定义的。这是班级:
public class DataGridCustomSort extends DataGrid
{
public function DataGridCustomSort()
{
super();
addEventListener(DataGridEvent.HEADER_RELEASE,
headerReleaseHandlerCustomSort,
false, EventPriority.DEFAULT_HANDLER);
}
public function headerReleaseHandlerCustomSort(event:DataGridEvent):void {
mx_internal::sortIndex = event.columnIndex;
if (mx_internal::sortDirection == null || mx_internal::sortDirection == "DESC")
mx_internal::sortDirection = "ASC";
else
mx_internal::sortDirection = "DESC";
placeSortArrow();
}
}
You have to specifically call the placeSortArrow() method when you get the HEADER_RELEASE event and set the column index and direction information.
获取HEADER_RELEASE事件并设置列索引和方向信息时,必须专门调用placeSortArrow()方法。
#3
0
in the above code what does "this" refer to is it the datagrid because I am confused by this.query.SortField , I am assuming 'this' and "query' are your own custom objects. and why are you checking for count. what count is that.
在上面的代码中,“this”引用的是datagrid,因为我对this.query.SortField感到困惑,我假设'this'和“query”是你自己的自定义对象。为什么要检查count。那是什么意思。
Regards -Mohan