java RichFaces 中的服务器端数据表排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/134742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Server-side DataTable Sorting in RichFaces
提问by sblundy
I have a data table with a variable number of columns and a data scroller. How can I enable server side sorting? I prefer that it be fired by the user clicking the column header.
我有一个包含可变列数和数据滚动条的数据表。如何启用服务器端排序?我更喜欢它由用户单击列标题触发。
<rich:datascroller for="instanceList" actionListener="#{pageDataModel.pageChange}"/>
<rich:dataTable id="instanceList" rows="10" value="#{pageDataModel}"
var="fieldValues" rowKeyVar="rowKey">
<rich:columns value="#{pageDataModel.columnNames}" var="column" index="idx">
<f:facet name="header">
<h:outputText value="#{column}"/>
</f:facet>
<h:outputText value="#{classFieldValues[idx]}" />
</rich:columns>
</rich:dataTable>
I already have a method on the bean for executing the sort.
我已经在 bean 上有一个方法来执行排序。
public void sort(int column)
采纳答案by sblundy
I ended up doing it manually. I adding a support tag to the header text tag, like so.
我最终手动完成了。我在标题文本标签中添加了一个支持标签,就像这样。
<h:outputText value="#{column}">
<a4j:support event="onclick" action="#{pageDataModel.sort(idx)}"
eventsQueue="instancesQueue"
reRender="instanceList,instanceListScroller"/>
</h:outputText>
To get the ascending/descending arrows, I added a css class.
为了获得升/降箭头,我添加了一个 css 类。
<h:outputText value="#{column}" styleClass="#{pageDataModel.getOrderClass(idx)}" >
<a4j:support event="onclick" action="#{pageDataModel.sort(idx)}"
eventsQueue="instancesQueue"
reRender="instanceList,instanceListScroller"/>
</h:outputText>
回答by Philipp
Your datamodel needs to implement "Modifiable" interface.
您的数据模型需要实现“可修改”接口。
The datatable will call it's modify()method to do serverside
sorting and filtering.
数据表将调用它的modify()方法来进行服务器端排序和过滤。
回答by Marco
There is a fairly elegant solution to this solution here:
这里有一个相当优雅的解决方案:
http://livedemo.exadel.com/richfaces-demo/richfaces/sortingFeature.jsf?tab=ex-usage
http://livedemo.exadel.com/richfaces-demo/richfaces/sortingFeature.jsf?tab=ex-usage
This demo avoids using the tag.
这个演示避免使用标签。
回答by Patrick
Have a look at the "sortBy" property of "rich:columns", maybe that's what you're looking for. Richfaces Reference
看看“rich:columns”的“sortBy”属性,也许这就是你要找的。 Richfaces 参考
回答by Shervin Asgari
Cant you just use Collection.sort() when you retrieve the List?
当您检索列表时,您不能只使用 Collection.sort() 吗?

