Date Filter
The Date Filter is a powerful feature in RevoGrid that allows you to filter data based on dates using a variety of criteria. It provides an intuitive interface for filtering dates with both standard comparison operators and relative date ranges.
Source code
import { defineCustomElements } from '@revolist/revogrid/loader';import { AdvanceFilterPlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';defineCustomElements();
import { currentTheme, useRandomData } from '../composables/useRandomData';
const { createRandomData } = useRandomData();const { isDark } = currentTheme();
export function load(parentSelector: string) { const grid = document.createElement('revo-grid');
grid.source = createRandomData(100); grid.columns = [ { name: '๐ ID', prop: 'id', }, { name: '๐
Date', prop: 'dateOfBirth', filter: ['date'], order: 'desc' }, { name: '๐ค Name', prop: 'fullName', } ];
// Define plugin grid.plugins = [AdvanceFilterPlugin, ColumnStretchPlugin];
grid.additionalData = { stretch: 'all' }; grid.filter = {}; grid.theme = isDark() ? 'darkMaterial' : 'material'; grid.hideAttribution = true; document.querySelector(parentSelector)?.appendChild(grid);}
<template> <VGrid class="cell-border" :theme="isDark ? 'darkMaterial' : 'material'" :columns="columns" :source="rows" :plugins="plugins" :additionalData="additionalData" :filter="true" style="min-height: 400px;" hide-attribution /></template>
<script setup lang="ts">import { ref } from 'vue';import { currentThemeVue } from '../composables/useRandomData';import { VGrid } from '@revolist/vue3-datagrid';import { AdvanceFilterPlugin, ColumnStretchPlugin, avatarRenderer, RowOddPlugin, RowSelectPlugin } from '@revolist/revogrid-pro';import { makeData } from '../composables/makeData';
const { isDark } = currentThemeVue();
const rows = ref(makeData(100));
const columns = ref([ { prop: 'avatar', cellTemplate: avatarRenderer, size: 60, filter: false, }, { name: '๐ค Name', prop: 'fullName', rowSelect: true, filter: false, }, { name: '๐
Date', prop: 'dateOfBirth', filter: ['date'], order: 'desc' }]);
const plugins = ref([AdvanceFilterPlugin, ColumnStretchPlugin, RowOddPlugin, RowSelectPlugin]);
const additionalData = ref({ stretch: 'all',});</script>
import React from 'react';import { ColumnRegular, RevoGrid } from '@revolist/react-datagrid';import { AdvanceFilterPlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';import { currentTheme, useRandomData } from '../composables/useRandomData';
const { createRandomData } = useRandomData();const { isDark } = currentTheme();
export default function FilterDateExample() { const columns: ColumnRegular[] = [ { name: '๐ ID', prop: 'id', }, { name: '๐
Date', prop: 'dateOfBirth', filter: ['date'], order: 'desc' }, { name: '๐ค Name', prop: 'fullName', } ];
const plugins = [AdvanceFilterPlugin, ColumnStretchPlugin]; const source = createRandomData(100); const additionalData = { stretch: 'all' };
return ( <RevoGrid theme={isDark() ? 'darkMaterial' : 'material'} columns={columns} source={source} plugins={plugins} additionalData={additionalData} filter={true} style={{ height: '400px' }} hideAttribution /> );}
import { Component, OnInit } from '@angular/core';import { RevoGrid } from '@revolist/angular-datagrid';import { AdvanceFilterPlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';import { currentTheme, useRandomData } from '../composables/useRandomData';
@Component({ selector: 'filter-date-angular', standalone: true, imports: [RevoGrid], template: ` <revo-grid [theme]="isDark ? 'darkMaterial' : 'material'" [columns]="columns" [source]="source" [plugins]="plugins" [additionalData]="additionalData" [filter]="true" style="height: 400px;" hideAttribution ></revo-grid> `})export class FilterDateComponent implements OnInit { columns = [ { name: '๐ ID', prop: 'id', }, { name: '๐
Date', prop: 'dateOfBirth', filter: ['date'], order: 'desc' }, { name: '๐ค Name', prop: 'fullName', } ];
plugins = [AdvanceFilterPlugin, ColumnStretchPlugin]; source = useRandomData().createRandomData(100); additionalData = { stretch: 'all' }; isDark = currentTheme().isDark();
ngOnInit() {}}
Features
- Standard date comparison operators (equals, before, after, etc.)
- Relative date ranges (today, this month, last quarter, etc.)
- Date range selection with From/To inputs
- Empty value handling
Filter Types
Standard Operators
- Equals - Matches a specific date
- Before - Matches dates before a specific date
- After - Matches dates after a specific date
- On or Before - Matches dates on or before a specific date
- On or After - Matches dates on or after a specific date
- Between - Matches dates in a range
- Not Equal - Matches dates not equal to a specific date
- Is Empty / Is Not Empty - Matches null/undefined/empty cells
Relative Date Ranges
- Today
- Yesterday
- Last 7 Days
- This Month
- Last Month
- This Quarter
- Next Quarter
- Previous Quarter
- This Year
- Next Year
- Previous Year
- Custom Period (user-defined)
Usage
To enable the date filter for a column:
- Add the plugin to your gridโs plugins array
import { AdvanceFilterPlugin } from '@revolist/revogrid-pro';
- Add the plugin to the gridโs plugins array:
plugins: [ AdvanceFilterPlugin,],
- Add โdateโ to the columnโs filter array:
import { AdvanceFilterPlugin } from '@revolist/revogrid-pro';const columns = [ { name: 'Event Date', prop: 'date', filter: ['date'], // Enable date filter }];
Filter Operators
Operator | Description |
---|---|
equals | Exact date match |
before | Dates before specified date |
after | Dates after specified date |
onOrBefore | Dates on or before specified date |
onOrAfter | Dates on or after specified date |
between | Dates within specified range |
notEqual | Dates not matching specified date |
isEmpty | Empty/null date values |
isNotEmpty | Non-empty date values |
today | Todayโs dates |
yesterday | Yesterdayโs dates |
last7Days | Dates within last 7 days |
thisMonth | Dates in current month |
lastMonth | Dates in previous month |
thisQuarter | Dates in current quarter |
nextQuarter | Dates in next quarter |
previousQuarter | Dates in previous quarter |
thisYear | Dates in current year |
nextYear | Dates in next year |
previousYear | Dates in previous year |