I've got a datatable along with sort, filter and columntoggler. Firstly, when I select and unselect a column in the same page everything is fine.
As you can see, my first column has disappeared
My problem here is when I go to the next page with pagination tool and if I want to unselect a column, it displays only the column header and not their rows as you can see below : The initial hidden column is now displayed but we've got a gap. The last column is right now empty and the first one take the value to the second column.
This is my datatable structure :
<p:dataTable id="datatable" var="mon" value="#{X.resultQuery}"
first="#{dataTableController.first}"
resizableColumns="true"
rows="20"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="30,40,50"
draggableColumns="true"
paginatorPosition="bottom"
selectionMode="single" rowKey="#{mon[4]}"
>
<f:facet name="header">
<p:commandButton id="toggler" type="button" value="Hide Columns" icon="ui-icon-calculator" />
<p:columnToggler datasource="datatable" trigger="toggler">
<p:ajax event="toggle" listener="#{columnTogglerController.onToggle}" />
</p:columnToggler>
</f:facet>
This is my ColumnTogglerController :
public class ColumnTogglerController implements Serializable {
private List<Boolean> list;
/**
* Creates a new instance of ColumnTogglerController
*/
public ColumnTogglerController() {
}
public List<Boolean> getList() {
return list;
}
public void setList(List<Boolean> list) {
this.list = list;
}
@PostConstruct
public void init() {
setList(Arrays.asList(true, true, true, true, true, true, true, true, true, true, true));
}
public void onToggle(ToggleEvent e) {
list.set((Integer) e.getData(), e.getVisibility() == Visibility.VISIBLE);
}
}
Basically my program is based on this blog : http://blog.primefaces.org/?p=3341
Thanks for you help.