Skip to main content

Date Filter

Date Filters allow you to filter date data.

Using Date Filter

Date filter is represented by class AgDateColumnFilter.

ColDef colDef = ColDef.builder()
.field("birthDate")
.filter(new AgDateColumnFilter())
.build()

Date Filter Parameters

Date Filters are configured though the filter params (DateFilterParams class)

PropertyTypeDefaultDescription
inRangeInclusivebooleanfalseIf true, the 'inRange' filter option will include values equal to the start and end of the range.
includeBlanksInEqualsbooleanfalseIf true, blank (null) values will pass the 'equals' filter option.
includeBlanksInNotEqualbooleanfalseIf true, blank (null) values will pass the 'notEqual' filter option.
includeBlanksInLessThanbooleanfalseIf true, blank (null) values will pass the 'lessThan' and 'lessThanOrEqual' filter options.
includeBlanksInGreaterThanbooleanfalseIf true, blank (null) values will pass the 'greaterThan' and 'greaterThanOrEqual' filter options.
includeBlanksInRangebooleanfalseIf true, blank (null) values will pass the 'inRange' filter option.
maxValidDateLocalDate-The maximum valid date that can be entered in the filter. If set, this will override maxValidYear - the maximum valid year setting.
maxValidYearInteger-This is the maximum year that may be entered in a date field for the value to be considered valid.
minValidDateLocalDate-The minimum valid date that can be entered in the filter. If set, this will override minValidYear - the minimum valid year setting.
minValidYearInteger1000This is the minimum year that may be entered in a date field for the value to be considered valid.

Example of using filter parameters.

ColDef colDef = ColDef.builder()
.field("birthDate")
.filter(new AgDateColumnFilter()
.filterParams(
DateFilterParams.builder()
.inRangeInclusive(true)
.includeBlanksInEquals(true)
.includeBlanksInNotEqual(true)
.includeBlanksInLessThan(true)
.includeBlanksInGreaterThan(true)
.includeBlanksInRange(true)
.maxValidDate(LocalDate.of(2030, Month.DECEMBER, 31))
.minValidYear(1970)
.build()
)
)
.build()

Date Filter Model

Date filter model is represented by DateFilterModel class.

If more than one Filter Condition is set, then multiple instances of the model are created and wrapped inside a Combined Model (CombinedSimpleModel<DateFilterModel>).

Grid using Server Side Date Filter

  • On column Birth Date, inRangeInclusive, includeBlanksInEquals, includeBlanksInNotEqual, includeBlanksInLessThan, includeBlanksInGreaterThan, includeBlanksInRange are all set to true
  • minValidYear is current - 1 and maxValidYear is current + 1
  • Source code for this grid available here
  • Backend source code available here
Loading grid...

Built-in Named & Relative Date Ranges

Date Filter supports a set of predefined named and relative date ranges to make common filtering tasks easier. These are ideal for users who want to filter by familiar time periods like "Last Week", "Year to Date", or "Next 30 Days"...

Enabling Built-in Date Ranges

info

Relative filters will respect these date filter parameters: includeBlanksInRange, maxValidDate, maxValidYear, minValidDate and minValidYear.

To enable the built-in date ranges, list them in the filterOptions in filterParams, otherwise relative filtering attempt will result to error.

import static io.github.smolcan.aggrid.jpa.adapter.filter.model.simple.SimpleFilterModelType.*;

ColDef colDef = ColDef.builder()
.field("birthDate")
.filter(new AgDateColumnFilter()
.filterParams(
DateFilterParams.builder()
.filterOptions(
today,
yesterday,
tomorrow,
thisWeek,
lastWeek,
nextWeek,
thisMonth,
lastMonth,
nextMonth
// ... and others
)
.build()
)
)
.build()

Available Built-in Named & Relative Date Ranges Options

You can see available options in official docs.

Option NameOption KeyTime Range Start >=Time Range End <
TodaytodayStart Of TodayStart Of Tomorrow
YesterdayyesterdayStart Of YesterdayStart Of Today
TomorrowtomorrowStart Of TomorrowStart Of Day After Tomorrow
This WeekthisWeekStart Of Current WeekStart Of Next Week
Last WeeklastWeekStart Of Previous WeekStart Of Current Week
Next WeeknextWeekStart Of Next WeekStart Of Week After Next
This MonththisMonthStart Of Current MonthStart Of Next Month
Last MonthlastMonthStart Of Previous MonthStart Of Current Month
Next MonthnextMonthStart Of Next MonthStart Of Month After Next
This QuarterthisQuarterStart Of Current QuarterStart Of Next Quarter
Last QuarterlastQuarterStart Of Previous QuarterStart Of Current Quarter
Next QuarternextQuarterStart Of Next QuarterStart Of Quarter After Next
This YearthisYearStart Of Current YearStart Of Next Year
Last YearlastYearStart Of Previous YearStart Of Current Year
Next YearnextYearStart Of Next YearStart Of Year After Next
Year to Date (YTD)yearToDateStart Of Current YearStart Of Tomorrow
Last 7 Dayslast7DaysStart of the day 7 days before todayStart Of Tomorrow
Last 30 Dayslast30DaysStart Of Today minus 30 daysStart Of Tomorrow
Last 90 Dayslast90DaysStart Of Today minus 90 daysStart Of Tomorrow
Last 6 Monthslast6MonthsStart Of Today minus 6 monthsStart Of Tomorrow
Last 12 Monthslast12MonthsStart Of Today minus 12 monthsStart Of Tomorrow
Last 24 Monthslast24MonthsStart Of Today minus 24 monthsStart Of Tomorrow

Example using Built-in Named & Relative Date Ranges

  • Column Birth Date has relative filters enabled
  • Option nextWeek is not listed in filterOptions on backend, using it will result to server error
  • Source code for this grid available here
  • Backend source code available here
Loading grid...