I am using primefaces 10 dataTable
and I am tring to filter on java.util.date column as follows:
<p:column field="dateCreated" headerText="Request Date" filterMatchMode="range">
<f:facet name="filter">
<p:datePicker widgetVar="dateFilterWidget" pattern="yyyy/MM/dd" selectionMode="range" onchange="dateFilterChange();">
<f:convertDateTime type="date" dateStyle="short" pattern="yyyy/MM/dd" />
</p:datePicker>
</f:facet>
<h:outputText value="#{requestItem.dateCreated}">
<f:convertDateTime pattern="yyyy/MM/dd hh:mm aa" locale="ar"/>
</h:outputText>
</p:column>
ISSUE : the filter works as date >= startDate and date < endDate
and i want it to work like : date >= startDate and date <= endDate
Example : i have request create on 1 October and request created on 7 october if i choose the range from :
2021/10/01 - 2021/10/07 the request from 2021/10/07 does not appear in filter result
so i tried to hack the code as follows:
function dateFilterChange(){
var datePicker = PF('dateFilterWidget');
console.log(datePicker.getDate());
if(datePicker.getDate() && datePicker.getDate().length == 2 && datePicker.getDate()[1]!= null){
var endDate = datePicker.getDate()[1];
endDate.setHours(23, 59, 59);
console.log('endDate :'+endDate);
}
console.log(datePicker.getDate());
PF('inboxTableWidget').filter();
}
but still getting same result.
You can also opt to take care of this on the server side.
The range filter is handled by org.primefaces.model.filter.RangeFilterConstraint. You can overload this class in your project and modify the isInRange method to check for Dates the way you want to.
Or, if you are using a LazyDataModel, simply act on the provided org.primefaces.model.FilterMeta of MatchMode RANGE.