How can I initially hide columns in a p:dataTable with p:columnToggler

前端 未结 4 1388
猫巷女王i
猫巷女王i 2020-12-11 02:50

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 d

4条回答
  •  长情又很酷
    2020-12-11 03:13

    In Primefaces 5.2 you can set the p:column visible attribute to false

    
    

    You can ofcourse use EL in the visible attribute by colum index (reordering becomes more difficult)

    
    

    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

    
    

    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

提交回复
热议问题