Forum Discussion
Property 'rolesIndex' does not exist on type 'DataViewMetadataColumn'
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-p4 years agoSuper 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_f3 years agoNew 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!
- dm-p3 years agoSuper User
Hi ryan_f,
I would suggest following the advice in my original reply to create an issue for the property to be correctly supported by MS, or contact [email protected] for an official response.
If you want to try this yourself in lieu of following this up, then I can (somewhat reluctantly) offer a possible approach, but no guarantees that it will work for your situation, as I don't have any details around your capabilities and how your dataRoles are named (or have they are mapped), but it may be enough for you to figure it out.
As such this approach assumes that in the rolesIndex property, I would see an object matching the role name, with an array of numbers (mine has a single digit entry, which I presume is the value you need), e.g.:
As the API doesn't type the property, you'll need to do this yourself, and based on this, I'd do something like the following to cast it:
interface IRoleIndex {[key: string]: number[]}; const roleIndex = (<IRoleIndex>column?.source?.['rolesIndex'])?.dataset?.[0];What I've done here is:
- Create an interface, IRoleIndex, which specifies flexible object keys, and a numeric array as its property (this could be done inline, but it makes the second line a bit harder to track, and also means the interface could be reused elsewhere.
- Access the rolesIndex property using bracket notation rather than dot notation. By doing this, TypeScript will allow me to access a property that is not part of the DataViewMetadataColumn interface definition from the API and will cast is an an any type. I then surround this with brackets, casting it to the IRoleIndex interface.
- After the bracket, attempt to acceess the property that correlates with my dataRole name, and then its first element.
- Note that as this is potentially volatile, I'm using optional chaining all the way through, so my code will at least execute. Although, you may need to handle casting a null or undefined result from this chain into a fallback value.
This may help you, but I'd still recommend following this up with MS if its a feature you want to be supported, as this may break from one version API to the next (or even as a result of changes to the developer visual rather than the APIs... which has been known to happen).Regards,Daniel