Primefaces Datatable (date column) Filter by calendar

前端 未结 4 1955
眼角桃花
眼角桃花 2021-02-06 15:41

I am using PF 5.1. I want to filter Primefaces datatable (date column) by calendar set primefaces calendar here . \"enter

4条回答
  •  情书的邮戳
    2021-02-06 16:10

    I have the requirement too on my site. However I have a different implementation from @stg. By the time of this writing, I'm using Primefaces 5.0. Here is the piece of work that does the job:

    XHTML site

    
       ...
    
       
             
                
                   
                   
                
             
          
             
          
       
    
    
    

    Java site

    @ManagedBean
    @SessionScoped
    public class Controller {
    
        public boolean filterByDate(Object value, Object filter, Locale locale) {
    
            if( filter == null ) {
                return true;
            }
    
            if( value == null ) {
                return false;
            }
    
            return DateUtils.truncatedEquals((Date) filter, (Date) value, Calendar.DATE);
        }
    }
    

    Site note

    • I'm using DateUtils.truncateEquals() because my date column contains timestamp. This is to ensure that I'm filtering on the particular date regardless of timestamp. If my input is date only then table view would be empty.
    • is needed to reset table view when the filter input is remove. I wasn't sure whether this is the correct way to handle this, I'm currently using it until I find a better one.

提交回复
热议问题