Cross filter - cant figure out how to emit filter #31197
Replies: 1 comment
-
Hey @datagene-github! I'm here to help you with any bugs, questions, or contributions you might have. Let's work together to solve this. To configure a chart to emit a filter in Apache Superset version 4.0.2, ensuring that the correct filter value is passed instead of the legend label, you should focus on the The Here's the relevant part of the code: const getCrossFilterDataMask =
(
selectedValues: Record<number, string>,
groupby: QueryFormColumn[],
labelMap: Record<string, string[]>,
) =>
(value: string) => {
const selected = Object.values(selectedValues);
let values: string[];
if (selected.includes(value)) {
values = selected.filter(v => v !== value);
} else {
values = [value];
}
const groupbyValues = values.map(value => labelMap[value]);
return {
dataMask: {
extraFormData: {
filters:
values.length === 0
? []
: groupby.map((col, idx) => {
const val = groupbyValues.map(v => v[idx]);
if (val === null || val === undefined)
return {
col,
op: 'IS NULL' as const,
};
return {
col,
op: 'IN' as const,
val: val as (string | number | boolean)[],
};
}),
},
filterState: {
value: groupbyValues.length ? groupbyValues : null,
selectedValues: values.length ? values : null,
},
},
isCurrentValueSelected: selected.includes(value),
};
}; The export const clickEventHandler =
(
getCrossFilterDataMask: (
value: string,
) => ContextMenuFilters['crossFilter'],
setDataMask: (dataMask: DataMask) => void,
emitCrossFilters?: boolean,
) =>
({ name }: { name: string }) => {
if (!emitCrossFilters) {
return;
}
const dataMask = getCrossFilterDataMask(name)?.dataMask;
if (dataMask) {
setDataMask(dataMask);
}
}; Ensure that |
Beta Was this translation helpful? Give feedback.
-
I am using apache superset version 4.0.2. I have a dashboard with different chart, and I enabled the cross filter, but when I click on a chart, the filter value that is passed (based on the query in the other charts) is the label of the legend of the chart I clicked on. when I checked online https://www.restack.io/docs/superset-knowledge-apache-superset-cross-filter I am supposed to configure the chart to emit filter, but I cant find where to do that
Beta Was this translation helpful? Give feedback.
All reactions