Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Dynamically creating filters on a dynamically generated CrossTab
MMirabito
One of my requirements is to allow users to define filters on the fly on a dynamically generated crossTab. <br />
<br />
I was able to figure out how to dynamically create filter on dataSets but I realized that this was not doing what users need. I think I need to create the filter at the xTab or datacube level but my problem is that I am not able to figure out how to programmatically access the name of the measure to build the filter. My code works properly on dataset filters.<br />
<br />
Bellow is the function that I built the ?<strong class='bbc'>filter</strong>? argument comes from the user?s browser i.e. (cases,gt,1000) I then break it apart to build the expression (I am also including the function that I use to create the measures). I think the issue is ?<strong class='bbc'>cases</strong>? the friendly name that the users sees which is also the measure name but at design time the Colum binding is something like ?<strong class='bbc'>cases_yearGroup/year_stateGroup/state</strong>? how can I get this from the objet model? I tried serveral permutations but I am coming up empty handed, is this even the proper approach?<br />
<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function insertFilter(reportDesignHandle, dataCubeName, filter) {
out.println("Begin insertFilter...");
var exp = filter.split(",");
var filter = new FilterCondition();
filter.expr = "row[\"" + exp[0] + "\"]";
//filter.expr = "data[\"" + exp[0] + "\"]";
filter.operator = exp[1];
filter.value1 = exp[2];
var cube = reportDesignHandle.findCube(dataCubeName)
cube.addFilter(filter);
out.println("End insertFilter...");
}
function insertMeasure(xTabHandle, cubeHandle, measureName, order, elementFactory) {
out.println("Begin insertMeasure...");
var measure = cubeHandle.getMeasure(measureName);
var mvh = xTabHandle.insertMeasure(measure, order);
mvh.getCell().getContents().get(0).setProperty("style", "xValues");
mvh.addHeader( );
var label = elementFactory.newLabel(null);
label.setText(measure.getDisplayName());
label.setProperty("style", "xMeasureHeader");
mvh.getHeader().addContent(label);
out.println("End insertMeasure...");
}
</pre>
<br />
As always thanks in advance for any suggestions.<br />
<br />
Max
Find more posts tagged with
Comments
JasonW
Max,
Try something like this:
measure = cubeHandle.getMeasure(params["Measure"].value);
mvh = xtabHandle.insertMeasure(measure, 0);
aggdata = mvh.getCell().getContents().get(0);
aggdata.setProperty("style", "mydata");
var fc = mvh.getModelHandle( ).getElementFactory( ).newFilterConditionElement( );
//fc.setExpr("data[\"PROFIT_Group1/PRODUCTLINE_Group2/year\"]");
fc.setExpr("data[\"" + aggdata.getResultSetColumn() +"\"]");
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_GT);
fc.setValue1("2000");
mvh.getModelHandle( ).add( "filter", fc );
Jason
MMirabito
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="69147" data-time="1286472345" data-date="07 October 2010 - 10:25 AM"><p>
Max,<br />
<br />
Try something like this:<br />
<br />
measure = cubeHandle.getMeasure(params["Measure"].value);<br />
mvh = xtabHandle.insertMeasure(measure, 0);<br />
<br />
aggdata = mvh.getCell().getContents().get(0);<br />
aggdata.setProperty("style", "mydata"); <br />
<br />
<br />
var fc = mvh.getModelHandle( ).getElementFactory( ).newFilterConditionElement( ); <br />
//fc.setExpr("data[\"PROFIT_Group1/PRODUCTLINE_Group2/year\"]");<br />
fc.setExpr("data[\"" + aggdata.getResultSetColumn() +"\"]");<br />
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_GT);<br />
fc.setValue1("2000");<br />
mvh.getModelHandle( ).add( "filter", fc );<br />
<br />
<br />
Jason<br /></p></blockquote>
<br />
<br />
Hi Jason,<br />
<br />
Just wanted to thank you for the example, this is a lot easier than my original try.<br />
For the sake of anyone else that may need a similar solution here is the code addopted from Jason's reply<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function insertFilter(xTabHandle, filter) {
out.println("Begin insertFilter...");
// Filter Format: col,operator,value1
var exp = filter.split(",");
var mvh = xTabHandle.getMeasure(exp[0]);
var colName = mvh.getCell().getContents().get(0).getResultSetColumn();
var fc = mvh.getModelHandle( ).getElementFactory( ).newFilterConditionElement( );
fc.setExpr("data[\"" + colName +"\"]");
// fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_LT);
fc.setOperator(exp[1]);
fc.setValue1(exp[2]);
mvh.getModelHandle().add( "filter", fc );
}
</pre>
<br />
Thanks again <br />
<br />
Max