mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Allows range filter for Date, DateTime columns
Summary: This diff is first of a series of 3 commits to enable range filering for Date and DateTime columns. Diff only enable setting date's min/max throw typing dates, Date picker and relative ranges are left for follow-up commits. - Exposes columns value formatter to the range input - Fixes column filter func to work with dates Test Plan: Adds Date to projects range filter test Adds Date/DateTime to nbrowser ColumnFilterMenu tests Reviewers: alexmojaki Reviewed By: alexmojaki Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3455
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import {CellValue} from "app/common/DocActions";
|
||||
import {FilterState, isRangeFilter, makeFilterState} from "app/common/FilterState";
|
||||
import {decodeObject} from "app/plugin/objtypes";
|
||||
import {isList, isListType, isNumberType} from "./gristTypes";
|
||||
import {isDateLikeType, isList, isListType, isNumberType} from "./gristTypes";
|
||||
|
||||
export type ColumnFilterFunc = (value: CellValue) => boolean;
|
||||
|
||||
// Returns a filter function for a particular column: the function takes a cell value and returns
|
||||
// whether it's accepted according to the given FilterState.
|
||||
export function makeFilterFunc(state: FilterState,
|
||||
columnType?: string): ColumnFilterFunc {
|
||||
columnType: string = ''): ColumnFilterFunc {
|
||||
|
||||
if (isRangeFilter(state)) {
|
||||
const {min, max} = state;
|
||||
if (isNumberType(columnType)) {
|
||||
if (isNumberType(columnType) || isDateLikeType(columnType)) {
|
||||
return (val) => {
|
||||
if (typeof val !== 'number') { return false; }
|
||||
return (
|
||||
|
||||
@@ -329,6 +329,10 @@ export function isNumberType(type: string|undefined) {
|
||||
return ['Numeric', 'Int'].includes(type || '');
|
||||
}
|
||||
|
||||
export function isDateLikeType(type: string) {
|
||||
return type === 'Date' || type.startsWith('DateTime');
|
||||
}
|
||||
|
||||
export function isFullReferencingType(type: string) {
|
||||
return type.startsWith('Ref:') || isRefListType(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user