Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chotu27
Post Patron
Post Patron

How to Build SelectionID for table visual (Source Code)

Hi ,

 

Can you anyone let me know how to build selectionId in table visual or direct me to its Source code.

2 ACCEPTED SOLUTIONS

@v-viig Hi Ignat,

 

I already shared you my complete source code to your messages can you please check that and give me reply.

 

View solution in original post

v-viig
Community Champion
Community Champion

Hello @chotu27

 

Code has been updated. Please take a llok at the private message.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

View solution in original post

9 REPLIES 9
v-viig
Community Champion
Community Champion

Please use this code as an example and current workaround:

getSelectionIds(dataView: DataView, host: IVisualHost): ISelectionId[] {
    return dataView.table.identity.map((identity: DataViewScopeIdentity) => {
        const categoryColumn: DataViewCategoryColumn = {
            source: dataView.table.columns[0],
            values: null,
            identity: [identity]
        };

        return host.createSelectionIdBuilder()
            .withCategory(categoryColumn, 0)
            .createSelectionId();
    });
}

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Hi Ignat

I tried to create selection id's with the workaround that you have sent. But its not working. The code just breaks at 

return host.createSelectionIdBuilder()
            .withCategory(categoryColumn, 0)
            .createSelectionId();
    });

statement giving no errors. I do not know how createSelectionIdBuilder is working. Please help 

v-viig
Community Champion
Community Champion

Hello @chotu27

 

Can you share source code? It that possible?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Hi @v-viig

I can share you apart of it. 

Here is the source code

 

Everything else seems to be working fine. It is only at that line where i am trying to create selection id's is what's not working.

//function for dataModelling
 public visualTransform(options: VisualUpdateOptions, host: IVisualHost):TableBarViewModel {
         let iValueFormatterPercent = ValueFormatter.create({ format: "0 %;-0%;0%" });   
         var dataViews =this.dataView = options.dataViews[0];
         let tableSelectionId: ISelectionId[] = this.getSelectionIds(dataViews,host);



//selection id function
public getSelectionIds(dataView: DataView, host: IVisualHost): ISelectionId[] {
 
return dataView.table.identity.map((identity: DataViewScopeIdentity) => {
const categoryColumn: DataViewCategoryColumn = {
source: dataView.table.columns[0],
values: null,
identity: [identity]
};
return host.createSelectionIdBuilder()
.withCategory(categoryColumn, 0)
.createSelectionId();
})
};


capabilities.json
"dataRoles": [
    {
      "displayName": "Values",
      "name": "values",
      "kind": "GroupingOrMeasure"
    }
  ],
  "dataViewMappings": [ 
    {    
      "conditions": [
        {
          "values": {
            "min": 1,
            "max": 25
          }
        }
      ],
       "table": {
          "rows": {
              "select": [{"for": { "in": "values" }}]
        }
    }
       }

  ],

 
v-viig
Community Champion
Community Champion

This code works well for me.

Are you sure that another part of the code works properly?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

@v-viig Hi Ignat,

 

I already shared you my complete source code to your messages can you please check that and give me reply.

 

v-viig
Community Champion
Community Champion

Hello @chotu27

 

Code has been updated. Please take a llok at the private message.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

Hello,

 

Could you please share with me your code?

Hello,

 

I see that selection for table requires some hack.

Hopefully, a new API 2.5 which will be released next week contains .withTable method of the builder that must solve selection issues with Table mapping.

 

Kind Regards,

 

Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
pbicvsupport@microsoft.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.