How to filter date in a custom field?


This is my custom field with the data type of Date, is it possible to make it filterable like the image below? where the date is able to select from the calendar.

Project name: Durian
Team name: Operations
Environment name: Production
Agent (forest package) name & version: “@forestadmin/agent”: “^1.16.2”,
Database type: PostgreSQL

Hi @Simon_Chen ,

This is possible but you will have to override each of the operator for the filter function.
Here is a snippet to show you how to override one operator:

    houses
      .addField("dateOfNow", {
        columnType: "Date",
        dependencies: ["id"],
        getValues: (records) => records.map(() => new Date()),
      })
      .replaceFieldOperator("dateOfNow", "Equal", (value) => {
        return {
          aggregator: "And",
          conditions: [
            {
              field: "example",
              operator: "Equal",
              value: new Date(value),
            },
          ],
        };
      });

Here is a second snippet with all the operators:

const basicOperators = ["Blank", "Equal", "Missing", "NotEqual", "Present"];
const dateOperators = [
  "Today",
  "Yesterday",
  "PreviousXDaysToDate",
  "PreviousWeek",
  "PreviousWeekToDate",
  "PreviousMonth",
  "PreviousMonthToDate",
  "PreviousQuarter",
  "PreviousQuarterToDate",
  "PreviousYear",
  "PreviousYearToDate",
  "Past",
  "Future",
  "PreviousXDays",
  "Before",
  "After",
  "BeforeXHoursAgo",
  "AfterXHoursAgo",
];
const timeOperators = ["LessThan", "GreaterThan"];
  [...basicOperators, ...timeOperators, ...dateOperators].forEach(
    (operator) => {
      houses.replaceFieldOperator("dateOfNow", operator, (value) => {});
    }
  );

You will have to implement the filtering process for each operator that you want to use.

Best regards,

Shohan