I have some problems by updating a datatable with a commandButton.
I checked:
Primefaces - update datatable with commandButton doesn't work
but I don't see what is the problem:
I use a commandButton onclick to search with the globalFilter. The lazy loading is ok but the filter only works when I press search button and then, another update button to update de datatable .
The search button filter onclick. And the update button redirect onclick to getPaginator().setPage(0), that shows the update datatable. This is the only way I see to update the datatable
I've try to update form:datatable in comandButton and actionListener to bean.resetDatable() without success.
I need only to press search button and update datatable both together in one button.
<h:form id="myDataForm">
<p:dataTable id="MyData" rowStatePreserved="true"
var="varMyData"
value="#{MyData.MyDataLazyDataModel}" lazy="true" filterDelay="1000"
widgetVar="wMyData"
rowKey="#{MyData.id}"
paginator="true" paginatorPosition="bottom" rows="10"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
emptyMessage="No data" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search: " />
<p:inputText id="globalFilter" onkeypress="PF('wMyData').filter();" />
<p:commandButton value="Search" class="ui-button" icon="fa fa-search" onclick="PF('wMyData').filter();"
update=":myDataForm:MyData" actionListener="#{MyData.resetDatatable()}"/>
<p:commandButton value="Update" onclick="VarMyData.getPaginator().setPage(0);"/>
</p:outputPanel>
</f:facet>
<p:column id ="numdoc" headerText="ID number" sortBy="#{varMyData.idNumber}"
filterStyle="display:none" filterBy="#{varMyData.idNumber}" filterMatchMode="exact" >
<h:outputText value="#{varMyData.idNumber}" />
</p:column>
</datatable>
</form>
I've tried to reset with lazydatamodel to null and PrimeFaces.current(), but nothing.
myDataView.java
public MyDataLazyDataModel getMyDataLazyDataModel() {
if (myDataLazyDataModel == null) {
myDataLazyDataModel= new MyDataLazyDataModel(getListAll());
}
return myDataLazyDataModel;
}
public void setMyDataLazyDataModelT(MyDataLazyDataModel myDataLazyDataModel) {
this.myDataLazyDataModel = myDataLazyDataModel;
}
public String resetDatatable() {
//option1:
myDataLazyDataModel = null;
//option2
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("myDataForm:myData");
PrimeFaces.current().ajax().update("myDataForm:myData");
if (!dataTable.getFilters().isEmpty()) {
dataTable.reset();
PrimeFaces.current().ajax().update("myDataForm:MyData");
}
Thanks.