Forum Discussion
Property 'rolesIndex' does not exist on type 'DataViewMetadataColumn'
Hi,
I am working on a Power BI visual where I would like to access a DataViewMetaDataColumn's rolesIndex property. However, accessing this property in Visual Studio Code throws an error.
Property 'rolesIndex' does not exist on type 'DataViewMetadataColumn'.ts(2339)Current Version of Power BI Vis API: 3.8.0
My code looks like the following:
const columns = options.dataViews[0].metadata.columns;
const labels = columns.filter(col => col.roles.labels)
labels.sort((col1 ,col2) => col1.rolesIndex.labels[0] - col2.rolesIndex.labels[0])Idea is to sort these columns based on the label index.
Is this a bug or am I doing something wrong here? Please let me know.
4 Replies
- AnonymousNot applicable
A solution I found which fixes this issue is by making the columns variable type to any[].
const columns: any[] = options.dataViews[0].metadata.columns;However, this seems to be a Typescript fix to solve this issue, there might be a bug here.
- dm-pSuper User
Hi Anonymous,
Indeed, it looks like rolesIndex is not an officially supported property in the API for a DataViewMetadataColumn, so whilst you might have worked around it for now, it might not always be present (or consistent) in the developer visual. It's probably worth creating an issue for it to see if the team can add official support for it in the available interfaces. You may get an more official response this way also, as the team do not monitor the forums currently.
Regards,
Daniel
- ryan_fNew Member
Hi Daniel,
Just starting PBI custom visual development. rolesIndex seems to be the only way to determine the order/position of fields in an input.
Otherwise, the data in the dataView is ordered chronologically based on when the field was inserted into the input, regardless of its position in the field input.
I would like to order the columns of a table by position in the field input (like the default table) and need the indexes to do so. Do you know how that can be achieved without using the rolesIndex?
Please see screenshot for clarification.
Thanks!