From d515dda20bb287cc896db256585a154173bea414 Mon Sep 17 00:00:00 2001 From: Patricia Martinez Tilve Date: Tue, 17 Feb 2026 20:42:30 +0100 Subject: [PATCH] New input `initial-filter-function` in o-service-component --- _data/components/grid.yml | 2 +- _data/components/list.yml | 2 +- _data/components/otableData/00table.yml | 2 +- _data/components/service.yml | 5 +++ _data/components/tree.yml | 2 +- .../01-o-service.component.md | 37 +++++++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/_data/components/grid.yml b/_data/components/grid.yml index faa0eb343..f0f5d6da1 100644 --- a/_data/components/grid.yml +++ b/_data/components/grid.yml @@ -10,7 +10,7 @@ inheritedAttributes: [{ },{ component: "OServiceComponent", path: "components/service/service/api", - attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "quick-filter", "quick-filter-placeholder", "quick-filter-appearance", "pagination-controls", "page-size-options"] + attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "quick-filter", "quick-filter-placeholder", "quick-filter-appearance", "pagination-controls", "page-size-options","initial-filter-function"] }] attributes: [{ diff --git a/_data/components/list.yml b/_data/components/list.yml index 15764fffe..54756decc 100644 --- a/_data/components/list.yml +++ b/_data/components/list.yml @@ -9,7 +9,7 @@ inheritedAttributes: [{ },{ component: "OServiceComponent", path: "components/service/service/api", - attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "detail-button-in-row", "detail-button-in-row-icon", "edit-form-route", "recursive-edit", "edit-button-in-row", "edit-button-in-row-icon", "insert-button", "row-height", "insert-form-route", "recursive-insert", "quick-filter", "quick-filter-placeholder", "quick-filter-appearance", "pagination-controls", "page-size-options"] + attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "detail-button-in-row", "detail-button-in-row-icon", "edit-form-route", "recursive-edit", "edit-button-in-row", "edit-button-in-row-icon", "insert-button", "row-height", "insert-form-route", "recursive-insert", "quick-filter", "quick-filter-placeholder", "quick-filter-appearance", "pagination-controls", "page-size-options","initial-filter-function"] }] inheritedOutputs: [{ diff --git a/_data/components/otableData/00table.yml b/_data/components/otableData/00table.yml index bcbadb980..debcc2dfa 100644 --- a/_data/components/otableData/00table.yml +++ b/_data/components/otableData/00table.yml @@ -9,7 +9,7 @@ inheritedAttributes: [{ },{ component: "OServiceComponent", path: "components/service/service/api", - attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "detail-button-in-row", "detail-button-in-row-icon", "edit-form-route", "recursive-edit", "edit-button-in-row", "edit-button-in-row-icon", "insert-button", "row-height", "insert-form-route", "recursive-insert", "filter-case-sensitive", "quick-filter", "quick-filter-placeholder", "pagination-controls", "page-size-options"] + attributes: ["title", "visible", "enabled", "controls", "detail-mode", "detail-form-route", "recursive-detail", "detail-button-in-row", "detail-button-in-row-icon", "edit-form-route", "recursive-edit", "edit-button-in-row", "edit-button-in-row-icon", "insert-button", "row-height", "insert-form-route", "recursive-insert", "filter-case-sensitive", "quick-filter", "quick-filter-placeholder", "pagination-controls", "page-size-options","initial-filter-function"] }] attributes: [{ diff --git a/_data/components/service.yml b/_data/components/service.yml index fe6bbaf5e..1d17ce415 100644 --- a/_data/components/service.yml +++ b/_data/components/service.yml @@ -62,6 +62,11 @@ attributes: [{ default : "outline", required : "", description : "Indicates which of the mat-form-field different except in o-table component[appearance variants](https://v15.material.angular.io/components/form-field/overview#form-field-appearance-variants) will be used. except in the o-table component." +},{ + name: "initial-filter-function", + type: "() => Expression | { [key: string]: any }", + since: "15.8.3", + description: "Callback function that returns an initial filter to be applied on every query." }] diff --git a/_data/components/tree.yml b/_data/components/tree.yml index 667096aad..dbcbef6c2 100644 --- a/_data/components/tree.yml +++ b/_data/components/tree.yml @@ -6,7 +6,7 @@ apiTitle: "OTreeComponent" inheritedAttributes: [{ component: "OServiceBaseComponent", path: "components/service/service-base/api", - attributes: ["attr", "static-data", "service", "service-type","query-fallback-function", "query-method", "entity", "keys", "parent-keys", "columns", "query-on-init", "query-on-bind", "query-rows", "insert-method", "update-method", "paginated-query-method", "delete-method", "pageable", "store-state"] + attributes: ["attr", "static-data", "service", "service-type","query-fallback-function", "query-method", "entity", "keys", "parent-keys", "columns", "query-on-init", "query-on-bind", "query-rows", "insert-method", "update-method", "paginated-query-method", "delete-method", "pageable", "store-state", "initial-filter-function"] }] attributes: [{ diff --git a/docs/components/o_service_components/01-o-service.component.md b/docs/components/o_service_components/01-o-service.component.md index 3a92cdd64..e8653f057 100644 --- a/docs/components/o_service_components/01-o-service.component.md +++ b/docs/components/o_service_components/01-o-service.component.md @@ -37,6 +37,43 @@ export class MyComponent extends OServiceBaseComponent { row-height --> +## Initial-filter-function +The `initial-filter-function` input allows you to provide a callback function that returns an initial filter to be applied on every query performed by the component. This filter is merged with any other active filters (quick filter, filter builder) using a logical `AND` operation. + +The returned value can be either an OntimizeWeb **Expression** object (for complex, structured filter expressions) or a **plain key-value object** (for simple column-value filters). The component handles both cases automatically: + +* If the returned value is an Expression, it is combined with the existing filter expression using FilterExpressionUtils.OP_AND. +* If the returned value is a plain object, its properties are merged directly into the base filter object via object spread. + +This input is especially useful when you need to enforce a persistent filter condition regardless of user interactions, such as restricting data to the current user, a specific tenant, or a fixed business rule. + +**Examples** +```html + + ... + +``` + +```ts +import { Expression, FilterExpressionUtils } from 'ontimize-web-ngx'; + +// Returning a Expression (STARTDATE > 01/01/2010 AND < Today) +initialFilterFunction(): Expression { + const exp1 = FilterExpressionUtils.buildExpressionMoreEqual('STARTDATE', 1262304000000); + const exp2 = FilterExpressionUtils.buildExpressionLessEqual('STARTDATE', Date.now()); + return FilterExpressionUtils.buildComplexExpression(exp1, exp2, FilterExpressionUtils.OP_AND); +} + +//Returning a plain key-value object +initialFilterFunction(): { [key: string]: any } { + return { CUSTOMERTYPEID: 1 }; +} +``` + +**NOTE**: +* **Execution on every query**: The callback is invoked on every request made by the component, including pagination, sorting, and refresh actions. Ensure the function is lightweight and side-effect free. +* **Compatibility**: This input is available on all components that extend OServiceComponent, including o-table, o-grid, o-list, and similar data-bound components. + ## Navigation to record detail In the service components, the default action when user clicks a item is to trigger the navigation to its record detail. For changing this behaviour, the user can change the `detail-mode` input value using one of the following values `none`, `click` or `doubleclick`.