setting default value in primefaces datatable Filter

前端 未结 4 1288
日久生厌
日久生厌 2020-12-06 03:01

I am using primefaces v3.5.On the datatable I am using filter on one column. How can I set a default value to the filter while loading the page Itself.

4条回答
  •  感动是毒
    2020-12-06 03:44

    The correct solution is to use the filteredValue attribute of p:dataTable which contains the filtered collection together with filterValue attribute of p:column to show the filters configuration to the user.

    To keep your p:dataTable filters stored in your session bean, you have to keep also the filtered data. The p:dataTable wouldn't perform the initial sorting for you.

    Check this example JSF:

    
    
        
    
        
            #{e.user.id}
        
    
    

    Backed with this managed bean:

    @Named(value = "userListState")
    @SessionScoped
    public class UserListState implements Serializable{
        private Map filterState = new HashMap();
        private List filteredValue;
    
        public UserListState() {
        }
    
        public void onFilterChange(FilterEvent filterEvent) {
            filterState = filterEvent.getFilters();
            filteredValue =(List) filterEvent.getData();
        }
    
        public String filterState(String column) {
            return filterState.get(column);
        }
    
        public List getFilteredValue() {
            return filteredValue;
        }
    
        public void setFilteredValue(List filteredValue) {
            this.filteredValue = filteredValue;
        }
    }
    

提交回复
热议问题