Forum Discussion
How to implement selections based on a categorical dataviewmapping with multiple fields
Hi everyone,
Been trying to implement selections on my custom visual but somehow I cannot seem to make it work.
Context drillthrough works fine but the item selection just does not seem to be working.
Currently I am testing with 4 fields on the category and one measure only.
The logic that I have implemented is the following:
- For each of the measure values iterate through the 4 categories and add a new selection ID as for example:
for (var _i = 0; _i < categoricalDataView.values[0].values.length; _i++) {
...
...
categoricalDataView.categories.forEach((column: DataViewCategoryColumn) => {
const categorySelectionId = this.host.createSelectionIdBuilder();
categorySelectionId.withCategory(column, _i);
categorySelectionId.withMeasure(values[0].source.queryName);
_selectionIds.push(categorySelectionId.createSelectionId());
});
}
What is wrong here?
Thank you
6 Replies
- dm-pSuper User
Hi djpirra
It's difficult to analyse 100% without seeing the rest of your code, but typically the methods you're calling against categorySelectionId to create your selectionId should usually be chained together.
Can you try the following and see if it works?
categoricalDataView.categories.forEach((column: DataViewCategoryColumn) => { const categorySelectionId = this.host.createSelectionIdBuilder(); _selectionIds.push( categorySelectionId .withCategory(column, _i) .withMeasure(values[0].source.queryName) .createSelectionId() ); });If this isn't working, we might need to get a bit more detail, but let's start here.
Regards,
Daniel
- djpirraHelper III
Hi Daniel,
I have tried that approach too...
I cannot use all together because I need to be sending an array to each datapoint since I have several category fields right?
This is the output of console.log for the selection ID:
e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":2}]}[]"} ... ... ...- dm-pSuper User
Hi djpirra,
Based on my understanding of the original code, the output looks okay, although you typically shouldn't need an array for each data point; just a selectionId. However,this will depend on how you are mapping your data, and how you are intending to use it within the visual. I have perhaps wrongly assumed you just wanted an array of all selectionIds available.
Normally, I might have an object array of my categories/values, with the selectionId as an attribute of that particular element, but again, this would depend on my intended use case.
Are you able to share your code at all? It might be more helpful if I can see how you're building your view model and how you are using it when you draw your visual. It might be that we need to make some changes elsewhere and it would be good if I can provide a more targeted answer for you.
Thanks,
Daniel