Flex: DataGrid with database: arrows disappear
In Flex, I use the following code to enable sorting in the DataGrid (data is dumped and sorted by server).
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 great, except that the sorting arrows are not displayed. How can i do this?
Thank! / Niels
+1
source to share
3 answers
Here's an example, if that's what you're looking for: http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to -click-a-column /
It looks like you need to update the collection used by your datapiver.
+5
source to share
I faced the same problem and the only solution I found was to override the DataGrid and create a custom one. Here is the class:
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 need to specifically call the placeSortArrow () method when you receive the HEADER_RELEASE event and set the column index and direction information.
+1
source to share