Flex 自定义排序功能与服务器端支持
Flex 中可用的排序功能假设您可以访问所有数据,但我使用分页数据网格(带有自定义代码),数据网格绑定到 ArrayCollection 实例,在下一页调用我更改数据dataprovider 的数据和一切工作正常,但为了排序,我需要重写单击或事件,更好地重写 arraycollection 的排序方法
所有这些都是为了能够进行服务器端排序。
有人遇到过这种问题吗?
The sorting capabilities that are available in Flex assume that you have access to all the data, but I'm using a paginated datagrid (with custom code), the datagrid is binded to an ArrayCollection instance, on the next page call I change the data of the dataprovider and everything works ok, but for sorting I need to override the click or event better override the sort method of the arraycollection
All this is to be able to do a server-side sorting.
Has anyone faced this kind of issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下是我用来解决这个问题的步骤...这个解决方案的好处是我可以允许 Flex 与我一起“排序”,这使得排序方向图标在 DataGrid 上可见。
步骤:
使用DataGrid的headerRelease事件拦截“排序”请求。
保留列及其当前排序方向的本地映射...这模仿了 flex 对其排序所做的操作...因此所有列都以“升序”开始,然后仅在以下情况下切换方向连续单击给定列两次。这可能可以通过观察 flex 的内部结构来完成,但我不想尝试。
headerRelease 事件使用其事件中请求的列,以及先前请求的列和当前列排序方向的映射来决定是否更新本地映射中的排序方向。
调用服务器以获取适当排序的数据页。
此时,Flex 也想对数据进行排序...(除非您阻止了 headerRelease 事件的 Default() )...以允许 Flex 对数据进行“排序”而不弄乱任何内容,以便方向图标继续如果功能正常,您可以:
在服务器上的 SQL 结果集中添加一个“行 id”字段,它只是结果集中每个连续行的计数器,在排序和分页之后...这个 id无论应用哪种排序方向,都将始终为升序。
将 DataGridColumns 上的 sortCompareFunction 设置为使用此行 id 的“虚拟”排序...如下所示:
这将允许 Flex 运行整个“页面”并保持一切不变......所以它很高兴,你也很高兴,因为你有图标......
Here are the steps I used to solve this issue... the nice thing about this solution is that I can allow Flex to "sort" along with me, which keeps the sort direction icons visible on the DataGrid.
Steps:
use the headerRelease event of the DataGrid to intercept the "sort" request.
keep a local map of columns and their current sort directions... this is a mimic of what flex is doing on its sort... so all columns start out with "ascending", and then the direction is toggled only when a given column is clicked twice in a row. this could probably be done by watching the flex internal structures, but i didn't care to try that.
the headerRelease event uses the requested column from its event, along with the previous requested column and the map of current column sort directions to decide whether to update the sort direction in the local map.
make the call to the server to get the appropriately sorted page of data.
at this point, Flex wants to sort the data as well... ( unless you preventDefault() the headerRelease event )... to allow Flex to "sort" the data without messing anything up, and so that the direction icons continue to function properly, you can:
add a "row id" field to your SQL result set on the server, which is simply a counter for each sequential row in the result set, after it's been sorted and paged... this id will always be ascending, no matter what sort direction is applied.
set the sortCompareFunction on the DataGridColumns to a "dummy" sort that uses this row id... as such:
This will allow flex to run through the "page" and leave everything as is... so it's happy and you're happy because you have the icons...
我不确定我是否真正理解这个问题,但听起来您需要在服务器端进行排序。如果您没有将所有数据加载到 Flex 应用程序中,则无法对其进行排序。
I am not certain that I really understand the question, but it sounds like you need to do your sorting on the server-side. If you do not have all of the data loaded into the flex application, there is no way you could sort it.
我是这样理解这个问题的:
他在flex客户端中有一部分总数据。由于客户端不知道所有数据,因此无法在客户端完成排序。
他已经让服务器端排序工作起来了。
他现在需要做的是:当用户单击数据网格的标题时,他想要进行服务器调用并取回排序后的数据。
单击网格标题时的默认行为是数据在客户端排序。
这就是为什么他需要在客户端做一些事情。
我唯一发现的是:
一旦单击标题上的鼠标按钮(再次释放鼠标按钮),就会调用指定的 onHeaderRelease 函数。
示例函数。也许你可以从这里拿起
我希望这对你有帮助!
I understood the problem like this:
He has a part of the total data in the flex client. Because the client does not know all of the data, sorting can't be done client side.
He already has the serverside sorting working.
What he needs to do now is: When the user clicks on the header of the datagrid he wants to make a server call and get the sorted data back.
The default behaviour when the header of a grid is clicked is that the data is sorted client side.
So thats why he needs to to something client side.
The only thing I found was this:
The specified function onHeaderRelease is called as soon as the mousebutton on a header was clicked (the mousebutton was released again).
Example function. Maybe you can pick up from here
I hope this will help you!
我实现了以下解决方案,目前该解决方案运行良好,但可能还可以进行改进。
我扩展了 ArrayCollection 类并重写了排序 set/get 和刷新方法
}
I implemented the following solution, which at the moment is working pretty well, but probably there are improvements that can be made.
I extended ArrayCollection class and override the sort set/get and refresh method
}