Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am building an extension with allowing multiple dimensions and measurements:
<Dimension Label="Dimensions" DropTarget="Dimensions" Require="true" Multiple="true" />
<Measurement Multiple="true" />
I would like to know the number of dimensions and the number of measurements inside the javascript code. I can get the total number of columns out of Data.HeaderRows[0].length, but I can't seem to find the number of dimensions and measurements (or if each column is tagged with dimension/measurement). Any help would be appreciated. Thanks
Hi Peter,
I'm looking for the same and cannot find any solution. One workaround (dirty though) would be to check if Data.HeaderRows[0].[index] contains a paranthesis "(" coming from an aggregation function like sum( ) to identify it as measure, else as dimension. However, I wonder why there is not API function to obtain type of column..
- Ralf
Yea i was afraid there was no good solution to this....Thanks Ralf
Yes, but this works in most of the cases, hopefully.. 😉
As Ralf said you can check for brackets but there are edge cases where a user might just reference a field name and the only() function is implied that stated causing brackets checks to fail.
But if my memory serves me right cell rows that has the color property are expressions and vice versa.
this.Data.Rows[0][1].color <- if exists it's a expression.
Here is a helper function that I use whenever I want to enhance our data object with columnar data and some more meta data.
if (!Qva.Public.Wrapper.prototype.getData) {
Qva.Public.Wrapper.prototype.getData = function() {
var data = {},
header = this.Data.HeaderRows[0];
data.Rows = this.Data.Rows;
data.Column = Object.keys(data.Rows[0]).map(function(c) {
return data.Rows.map(function(r) {
return r
});
});
data.Column.forEach(function(element, index) {
element.type = element[0].color === undefined ? "expression" : "dimension";
element.label = header[index].text;
});
return data;
};
}
Hi Alexander,
thanks, this seems to be workable. However, I do see color and value properties only for dimensions and not for expressions (and I wonder what the value means here).. So, what is wrong?
- Ralf
And what's even more strange, the color code changes randomly..
- Ralf
Hi Alexander,
thanks for the color hint. Now I use this simple line of code to determine the amount of dimensions:
// get amount of Dimensions | |||||
var nDimensions = this.Data.Rows[0].filter(function(col){return !(col.color == undefined);}).length; |
- Ralf