可以使用以下方式将任何组件放入列标题中facet
。但是,不可能仅请求数据表主体刷新。所以解决方案是,发送正常请求,但接管响应并在自定义代码部分处理它。
如果你像这样创建remoteCommand:
<p:remoteCommand id="refreshDataTable" name="refreshDataTable"
actionListener="#{carTable.doFilter}"
update="dataTable" />
该命令的 ID 被发送到服务器。知道了这一点,我们就可以准备自定义 AJAX 请求了:
var options = {
source: 'main:tabView:refreshDataTable',
update: carsTable.id,
formId: carsTable.cfg.formId
}
options.onsuccess = customHandler
PrimeFaces.ajax.AjaxRequest(options);
其中 customHandler 代码如下所示:
var xml = $(resp.documentElement)
updates = xml.find('update')
for(var i=0; i < updates.length; i++) {
var update = updates.eq(i),
id = update.attr('id'),
content = update.text();
if(id == carsTable.id){
var tbody = $(content).find('tbody')
carsTable.tbody.html(tbody.html());
}
else {
PrimeFaces.ajax.AjaxUtils.updateElement.call(this, id, content);
}
PrimeFaces.ajax.AjaxUtils.handleResponse.call(this, xml);
var paginator = carsTable.getPaginator();
if(paginator) {
paginator.setTotalRecords(this.args.totalRecords);
}
if(carsTables.cfg.scrollable) {
carsTable.alignScrollBody();
}
return true;
我们需要在Java代码中设置变量totalRecords:
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("totalRecords", filteredCars.size());