@Master_T , You can also go one step further and iterate through all data roles using an extension of your code.
dataView.metadata.columns.forEach(col => {
let rolesIndex = col['rolesIndex'];
console.log("rolesIndex:", rolesIndex )
if (rolesIndex) {
// Iterate through the roles
Object.keys(rolesIndex).forEach(roleName => {
console.log(`Role Name: ${roleName}`);
// Iterate through the indices for this role
rolesIndex[roleName].forEach(index => {
console.log(`Role Index for ${roleName}: ${index}`);
});
});
} else {
console.log("rolesIndex is undefined for this column.");
}
});
Note that we need to be cautious using this approach since it is not using the published api and it is possible it could change in future, but my understanding is that this is the only way it is currently possible to determine the order of the columns, so I will be using it until it either breaks or is replaced by an "approved" method.