gristlabs_grist-core/app/client/models/entities/FilterRec.ts
George Gevoian 7fe4423a6f (core) Allow filtering hidden columns
Summary:
Existing filters are now moved out of fields
and into a new metadata table for filters, and the
client is updated to retrieve/update/save filters from
the new table. This enables storing of filters for
columns that don't have fields (notably, hidden columns).

Test Plan: Browser and server tests.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3138
2021-11-22 10:26:08 -08:00

23 lines
956 B
TypeScript

import {ColumnRec, DocModel, IRowModel, refRecord, ViewSectionRec} from 'app/client/models/DocModel';
import * as modelUtil from 'app/client/models/modelUtil';
import * as ko from 'knockout';
// Represents a column filter for a view section.
export interface FilterRec extends IRowModel<"_grist_Filters"> {
viewSection: ko.Computed<ViewSectionRec>;
column: ko.Computed<ColumnRec>;
// Observable for the parsed filter object.
activeFilter: modelUtil.CustomComputed<string>;
}
export function createFilterRec(this: FilterRec, docModel: DocModel): void {
this.viewSection = refRecord(docModel.viewSections, this.viewSectionRef);
this.column = refRecord(docModel.columns, this.colRef);
// Observable for the active filter that's initialized from the value saved to the server.
this.activeFilter = modelUtil.customComputed({
read: () => { const f = this.filter(); return f === 'null' ? '' : f; }, // To handle old empty filters.
});
}