问题描述
我有一个数据表,需要显示大量数据集.所以我决定使用primefaces实时滚动.我还知道为了提高具有大量数据集的数据表性能,我们需要实现延迟加载.参考primefaces 展示示例这里,我在声明中观察到的内容
I have a datatable where huge data sets need to be displayed.So i decided to go with primefaces live scrolling.I also got to know that to improve datatable performance with huge data sets we need to implement lazy loading.With reference to the primefaces showcase examplehere,what i observed that there in the statement
,当分页、排序、过滤或实时滚动发生时,需要实现一个LazyDataModel来查询数据源
提到了实时滚动,但我看不到处理滚动的代码.它只有处理排序、过滤、行计数和分页的代码.如果实时滚动和惰性数据模型实现都兼容,有人可以澄清我的困惑吗?或者我应该添加一些代码来处理实时滚动.
live scrolling is mentioned but i cannot see the code to handle scrolling.It only has the code to handle sorting,filtering,row count and pagination.Can someone please clarify my confusion if both live scolling and lazy datamodel implementation are compatible with each other or should i add some code to handle live scrolling also.
推荐答案
它的工作原理与分页完全相同.
It works exactly the same as if you were having a pagination.
这是一个小例子:
xhtml
<p:dataTable var="user"
value="#{bean.lazyDataModel}"
scrollRows="20"
liveScroll="true"
scrollHeight="500"
lazy="true"
scrollable="true">
<p:column headerText="name">
<h:outputText value="#{user.name}" />
</p:column>
</p:dataTable>
Bean
@ManagedBean
@ViewScoped
public class Bean {
private LazyDataModel<User> lazyDataModel;
@EJB
UserEJB userEJB;
@PostConstruct
public void init() {
lazyDataModel = new LazyUserModel(userEJB);
}
public LazyDataModel<User> getLazyDataModel() {
return lazyDataModel;
}
public void setLazyDataModel(LazyDataModel<User> lazyDataModel) {
this.lazyDataModel = lazyDataModel;
}
//setters and getters for userEJB
}
LazyUserModel
public class LazyUserModel extends LazyDataModel<User> {
private Integer findAllCount;
@EJB
private UserEJB userEJB;
public LazyUserModel(UserEJB userEJB) {
this.userEJB = userEJB;
}
@Override
public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder,
Map<String, String> filters) {
List<User> data = new ArrayList<User>();
// pageSize is scrollRows="20" in the datatable
data = userEJB.findAll(first, pageSize);
// findAll is using query.setFirstResult(first).setMaxResults(pageSize).getResultList()
// rowCount
if (findAllCount == null) {
findAllCount = userEJB.findAllCount();
this.setRowCount(findAllCount);
}
return data;
}
}
希望这会有所帮助.
这篇关于primefaces 实时滚动是否与延迟加载兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!