When I am trying to delete an existing row in the data table it deleted successfully. But once I am trying to add a new row in the same session it edit the last row in the table, however it's already added in the list.
<p:dataTable id="AllData" var="itemTypeVar" value="#{itemTypeBean.itemTypesList}" sortBy="#{itemTypeVar.itemTypeId}"
editable="true" paginator="#{common.paginator}" rows="#{common.rows}"
paginatorTemplate="#{common.paginatorTemplate}"
rowsPerPageTemplate="#{common.rowsPerPageTemplate}"
paginatorPosition="#{common.paginatorPosition}" styleClass="sClass ui-datatable-hor-scroll"
widgetVar="allData">
<p:column headerText="#{docBundle.delete}" style=" height: auto;width:60px;text-align: center;">
<p:commandLink action="#{itemTypeBean.delete(itemTypeVar)}" update=":Form_Data:AllData :Form_Mesages" oncomplete="PF('allData').clearFilters()" />
<p:commandButton actionListener="#{itemTypeBean.addRecord}" id="add" value= "#{docBundle.add}" update=":Form_Data :Form_Mesages" style="margin-top: 5px;" oncomplete="jQuery('.ui-datatable-data tr').last().find('span.ui-icon-pencil').each(function(){jQuery(this).click()}); " />
bean:
public void delete(InvStpItemType deleted) {
RequestContext context = RequestContext.getCurrentInstance();
itemStpTypeCurrent = new InvStpItemType();
itemStpTypeCurrent = deleted;
try
{
if (itemStpTypeCurrent.getItemTypeId() != 0) {
invStpItemTypeFacade.remove(deleted);
itemTypesList.remove(itemStpTypeCurrent);
Messages.deleteSuccMsg(this.getLanguage());
} else {
itemTypesList.remove(itemStpTypeCurrent);
}
}
catch(Exception ex)
{
Messages.errorMsg(getLang(), "canNotDeletedUsedByItems");
}
}
public void addRecord() {
if (!addRecord) {
addRecord = true;
itemStpTypeCurrent = new InvStpItemType();
itemStpTypeCurrent.setActive("A");
itemTypesList.add(itemStpTypeCurrent);
Utilities.getLastPagination(":Form_Data:AllData");
}
else{ Utilities.getLastPagination(":Form_Data:AllData");}
}
I removed ' oncomplete="PF('allData').clearFilters()" ' from my ْXHTML code and reset the datatable from my ْBean code and it works well... if u have a better solution don't hesitate to post it .
DataTable dataTable = (DataTable)FacesContext.getCurrentInstance().getViewRoot().findComponent(":Form_Data:AllData");
dataTable.reset();