<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ag-grid/13.3.1/ag-grid.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
</head>
<body>
Ag Grid: Out of the box DATE complete column filters
<div id="myGrid" class="ag-fresh" style="height: 100%;"></div>
<script src="script.js"></script>
</body>
</html>
// Code goes here
var columnDefs = [{
headerName: "Date",
field: "datecustom",
width: 150,
filter: 'date',
filterParams: {
filterOptions: ['equals', 'notEqual', 'lessThan', 'lessThanOrEqual', 'greaterThan', 'greaterThanOrEqual', 'inRange'],
// use inRangeInclusive: true for the range filter to include the selected
// from and to dates. Setting it false would fetch only the inbetween dates
inRangeInclusive: true,
comparator: function(filterLocalDateAtMidnight, cellValue) {
//using moment js
var dateAsString = moment(cellValue).format('DD/MM/YYYY');
var dateParts = dateAsString.split("/");
var cellDate = new Date(Number(dateParts[2]), Number(dateParts[1]) - 1, Number(dateParts[0]));
if (filterLocalDateAtMidnight.getTime() == cellDate.getTime()) {
return 0
}
if (cellDate < filterLocalDateAtMidnight) {
return -1;
}
if (cellDate > filterLocalDateAtMidnight) {
return 1;
}
}
}
}];
var rowData = [
{datecustom: '2017-10-03 12:18:55'},
{datecustom: '2017-10-01 16:53:04'},
{datecustom: '2017-09-27 13:39:47'},
{datecustom: '2016-01-26 13:39:47'},
{datecustom: '2016-03-23 13:39:47'},
{datecustom: '2015-02-26 08:24:48'},
{datecustom: '2015-08-21 08:24:48'}
];
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData,
enableFilter: true,
enableColResize: true
};
// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
});
The example explains implementing the ag-grid(https://www.ag-grid.com/) 'date' column filter
['equals', 'notEqual', 'lessThan', 'lessThanOrEqual', 'greaterThan', 'greaterThanOrEqual', 'inRange']
// @author: Bala Malireddi