Primefaces Datatable (date column) Filter by calendar

前端 未结 4 1958
眼角桃花
眼角桃花 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:34

    For older PrimeFaces versions the solution has to be implemented like in this answer, for newe versions the other answer contains the solution.

    Basically, this can be achieved like this:

    • use a hidden input field (like h:inputHidden) in the filter facet to hide the default filter input field
    • put a p:calendar in the header facet
    • add a dateSelect event onto your calendar. In onstart replace the value of your hidden input by the value of the calendar. In oncomplete use the client side API to filter your datatable
    • write your custom filter function to compare the object value and the filter value as required

    Note that the p:calendar is meant to be for client input of a date only. If you also need the correct time in your filter function consider using an additional TimePicker (e.g. http://www.primefaces.org/showcase-ext/sections/timePicker/basicUsage.jsf)

    Edit: Actually, PrimeFaces calendar supports datetime in mode="datetime". I wasn't aware of this. See https://code.google.com/p/primefaces/issues/detail?id=648

提交回复
热议问题