Hi, trying to write a parent / child filter, with ...
# gooddata-ui
m
Hi, trying to write a parent / child filter, with this code from docs example. import React, { useState } from "react"; import { AttributeFilter } from "@gooddata/sdk-ui-filters"; import { BarChart } from "@gooddata/sdk-ui-charts"; import { attributeDisplayFormRef, idRef, modifyMeasure, newNegativeAttributeFilter } from "@gooddata/sdk-model"; import * as Md from "../md/full"; const idAttributeIdentifier = "label.all_vehicles.corr_make"; const FinRental = modifyMeasure(Md.FinRental.Avg, (m) => m.format("#,##0.00").alias("Fin Rental").title("Fin Rental")); export const AttributeParentChildFilter = () => { const [filter, setFilter] = useState(newNegativeAttributeFilter(attributeDisplayFormRef(Md.CorrModel), { uris: [] })); const [parentFilter, setParentFilter] = useState( newNegativeAttributeFilter(attributeDisplayFormRef(Md.CorrMake), { uris: [], }), ); const onError = (...params) => { // eslint-disable-next-line no-console console.info("AttributeFilterExample onLoadingChanged", ...params); }; const onLoadingChanged = (...params) => { // eslint-disable-next-line no-console console.info("AttributeFilterExample onLoadingChanged", ...params); }; console.log(parentFilter, filter); return ( <div className="s-attribute-filter"> <AttributeFilter filter={parentFilter} fullscreenOnMobile={false} onApply={setParentFilter} /> <AttributeFilter filter={filter} parentFilters={parentFilter ? [parentFilter] : []} parentFilterOverAttribute={idRef(idAttributeIdentifier)} fullscreenOnMobile={false} onApply={setFilter} /> <div style={{ height: 300 }} className="s-line-chart"> <BarChart measures={[FinRental]} viewBy={Md.CorrModel} filters={[filter, parentFilter]} onLoadingChanged={onLoadingChanged} onError={onError} /> </div> </div> ); }; But it gives error in the console, see screenshot. Might be related to line parentFilterOverAttribute={idRef(idAttributeIdentifier)} Did I miss a step?
m
Hello @Michael Serres, it seems related to
parentFilterOverAttribute
as you are saying. It should be likely:
Copy code
attr.all_vehicles.corr_make
as
parentFilterOverAttribute
needs to be attribute identifier, not a display form identifier. Let me know if it helped.
m
Tried using const idAttributeIdentifier = "attr.all_vehicles.corr_make"; but getting same error., using bear backend, gd.ui via react project starter.
m
And is the connecting attribute identifier correct? What is the 400 error response, is there some additional info?
m
Putting that url in browser I get:
Copy code
{
  "error": {
    "component": "Resource::Elements::Service",
    "errorClass": "GDC::Exception::User",
    "message": "wrong dimensionalities in image: subtree={\"subset\":{\"dim\":[\"2870\"],\"what\":\"attribute\",\"set\":[148048]}} over=2870 to=2874 ast={type=image,value=undefined,content=[...]}",
    "parameters": [],
    "requestId": "qV83gjt67QUN7Ehu:oix654ruq58vnfrk"
  }
}
It's a flat table, column corr_make and corr_model @Matyáš Kandl
@Dan Homola
d
In your model, is the
attr.all_vehicles.corr_make
on the path between the parent and child attributes? For example in my demo model on the picture, I can limit the values of EmployeeName by LocationName connecting them using the LineItemId attribute. Please make sure there is a path between your two attributes like that.
m
Thanks @Dan Homola. Makes sense. So it won't work on a flat table, data like this: corr_make | corr_model Peugeot | 208 Peugeot | 308 Nissan | Lead Ford | Focus I'm used to BI tools, showing in filters, make distinction between possible values and impossible values, as user makes selections. What's a good way to do that? to avoid selection that gives "no data".
d
You should be able to make it work also on the flat table: use the key attribute of the table with the attributes you want to “connect” as the
parentFilterOverAttribute
. Continuing the example I gave above: to restrict
LocationName
by
LocationCity
I can use the
LocationId
attribute (notice it is the key of the table). So in your case to restrict
label.all_vehicles.corr_model
by
label.all_vehicles.corr_make
you need to use the key attribute of your car table. Does this make sense? 🙂
m
Yes, you're absolutely right, changing code to const idAttributeIdentifier = "attr.all_vehicles.idx"; works! Awesome! @Dan Homola
Can this be generalised to all filter fields? To show only "possible values" after filters are set? ie adding parent / parentFilterOverAttribute to all filter components?
d
I’m glad it works 🙂 the more general approach is also possible, but you still need to be explicit about which filters are parents to which. To specify different
parentFilterOverAttribute
for each parent filter (which will likely be necessary), you can use the function version of the
parentFilterOverAttribute
prop: https://sdk.gooddata.com/gooddata-ui-apidocs/docs/sdk-ui-filters.iattributefilterprops.parentfilteroverattribute.html