Flex: Database driven DataGrid: arrows disappearing

房东的猫 提交于 2020-02-05 05:35:51

问题


In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).


        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


回答1:


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/

It looks like you need to refresh the collection used by your dataprovider.




回答2:


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:

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.




回答3:


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.

Regards -Mohan



来源:https://stackoverflow.com/questions/323147/flex-database-driven-datagrid-arrows-disappearing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!