useAttributeFilterHandler
Access the IMultiSelectAttributeFilterHandler Core API directly for low-level attribute filter control.
Lower-level hook for accessing the IMultiSelectAttributeFilterHandler Core API directly. This is @beta.
Use this when you need direct access to the handler instance rather than the higher-level controller. For most custom filter UIs, prefer useAttributeFilterController which provides a more convenient interface.
Basic usage
import { useAttributeFilterHandler } from "@gooddata/sdk-ui-filters";
import { useBackendStrict, useWorkspaceStrict } from "@gooddata/sdk-ui";
function MyFilterHandler({ filter }) {
const backend = useBackendStrict();
const workspace = useWorkspaceStrict();
const handler = useAttributeFilterHandler({
backend,
workspace,
filter,
});
if (!handler) {
return <div>Text (arbitrary or match) filters are not supported by this hook.</div>;
}
// Use handler's Core API directly
// See IMultiSelectAttributeFilterHandler for available methods
return <div>{/* Custom filter UI using handler */}</div>;
}
Parameters
The hook takes one IUseAttributeFilterHandlerProps object, listed under Props. backend, workspace, and filter are required.
displayAsLabelsets the label to display the elements as.hiddenElementslists elements to hide from the filter, in the same form as the filter elements: values for a value-based filter. On GoodData Cloud and GoodData.CN, a value is the element’s primary key.staticElementsreplaces the elements loaded from the backend.withoutApplyapplies changes immediately, without confirmation.
Return value
IMultiSelectAttributeFilterHandler | null
| Value | When |
|---|---|
IMultiSelectAttributeFilterHandler | filter is a positive or negative (elements) attribute filter. The hook creates the handler synchronously during the first render. |
null | filter is an arbitrary or match (text) attribute filter when the handler is created. The hook creates no handler for these filter types. |
The hook does not load any data. Call handler.init() to load the attribute, the selected elements, and the initial elements page. init() cancels a running initialization, if any, and starts it again.
Notes
backendandworkspaceare required. The hook does not read them fromBackendProviderorWorkspaceProvider. UseuseBackendStrictanduseWorkspaceStrict, as in the example, to take them from context.- The handler always uses the
"multi"selection mode. withoutApplydefaults tofalse.useAttributeFilterControlleruses this hook internally and callsinit()for you. It also handles parent filters, element limits, placeholders, and text filters.
When it re-runs
The hook re-creates the handler (a new instance, which you must initialize again) when any of these change:
| Input | Compared by |
|---|---|
backend | Reference |
workspace | Value |
filter | Display form only. The handler is re-created when the filter display form differs from both the handler’s current filter and the filter it was initialized with. A change of the selected elements alone does not re-create the handler. |
staticElements | Deep equality |
hiddenElements | Deep equality |
Changes of displayAsLabel or withoutApply alone do not re-create the handler.
The hook subscribes to handler.onUpdate and re-renders your component on every handler update. The subscription is removed when the handler changes and on unmount.
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
backend | IAnalyticalBackend | Yes | — | — |
filter | IAttributeFilter | Yes | — | — |
workspace | string | Yes | — | — |
displayAsLabel | ObjRef | No | — | — |
hiddenElements | string[] | No | — | — |
staticElements | IAttributeElement[] | No | — | — |
withoutApply | boolean | No | — | — |
Related
Build fully custom attribute filter UIs with SDK-managed state, elements loading, and apply callbacks.
Configure AttributeFilter with a filter definition or placeholder, handle selection changes, choose selection behavior, and replace its UI components.
Split an IFilter array by kind, find the filter for a display form, read or replace the selected elements, and detect an empty selection without reading filter internals.