I'm using PrimeFaces v.5 with this version a new component is released that ColumnToggler, when view is rendered, refreshed all checkbox are checked as a default operation.
What I need to do is;
p:columnToggler
remember checked and unchecked options when a refresh operation occurs on p:dataTable
DataTables and show and hide columns dynamically through use of this option and the column(). visible() / columns(). visible() methods. This option can be used to get the initial visibility state of the column, with the API methods used to alter that state at a later time.
$(document). ready(function () { $('#example'). DataTable({ columnDefs: [ { target: 2, visible: false, searchable: false, }, { target: 3, visible: false, }, ], }); });
In Primefaces 5.2 you can set the p:column visible attribute to false
<p:column ... visible="false">
You can ofcourse use EL in the visible
attribute by colum index (reordering becomes more difficult)
<p:column ... visible="#{visibilityModel.visibleList[1]}">
It hides the column at the beginning depending on the return value and you can show/hide the column through the columnToggler checkbox
By using the ajax toggle event
<p:ajax event="toggle" listener="#{viewBean.onToggle}" />
You can update the state of the visibilityModel server side
public void onToggle(ToggleEvent e) {
list.set((Integer) e.getData(), e.getVisibility() == Visibility.VISIBLE);
}
See this PrimeFaces blog entry for full example to actually keep/store the state of the visibility server side so it can be reused later
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With