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 modifying a data set filter with JavaScript
mogwai
<p>I have a data set created by a lengthy union of half a dozen tables.</p>
<p>I want the user to be able to filter this data set on multiple or all districts.</p>
<p>I created a multi-select report parameter which allows me to select several districts. This works fine.</p>
<p>I would like to add the default value 'All' so that the filter actually doesn't filter.</p>
<p> </p>
<p>Is there a way to do this?</p>
<p> </p>
<p>I was hoping there was way to modify the filter using JAvaScript in the BeforeOpen event script.</p>
<p>Another option would be to use JavaScript in the actual filter condition itself but I'm not sure which JavaScript would do the trick.</p>
<p> </p>
<p>Modifying the query text is too cumbersome because I would have to parse every table union.</p>
Find more posts tagged with
Comments
GLO_FR
<p>Hi,</p>
<p> </p>
<p>why didn't you use the filter option in your union dataset ?</p>
<p> </p>
<p>If the filter has to be dynamic, type everything in the function windows with some JS code and set the result to true or false.</p>
<p> </p>
<p> </p>
<p> </p>
mogwai
<p>I'm not sure how this would work. Currently I have a filter on the union data set. It is</p>
<p> </p>
<p>row["district_ID"] In params["geoScope"].value</p>
<p> </p>
<p>geoScope is a dynamic multi-select report parameter listing all the districts</p>
<p> </p>
<p>This works fine but to get all the districts I must select them all.</p>
<p> </p>
<p>What I am trying to accomplish is a filter that does this:</p>
<p> </p>
<p>if params["geoScope"].value == "All" don't apply any filter</p>
<p>else apply filter row["district_ID"] In params["geoScope"].value</p>
<p> </p>
<p>How can I do this using the data set filter option?</p>
GLO_FR
<p>Ok,</p>
<p> </p>
<p>So write some JS like this in the function window (not tested yet)</p>
<pre class="_prettyXprint _lang-js">
if(params["geoScope"].value=="All") true
else if (params["geoScope"].value.join('/').search(row["district ID"])) > -1 true
else false
</pre>
<p>and set the operator in the filter window to "is True"</p>
mogwai
<p><span style="font-family:arial, helvetica, sans-serif;"><span style="font-size:14px;">Thanks Guillaume. This works beautifully. I couldn't get </span></span></p>
<p> </p>
<p><span>if</span><span>(</span><span>params</span><span>[</span><span>"geoScope"</span><span>].</span><span>value</span><span>==</span><span>"All"</span><span>)</span><span> </span><span>true</span></p>
<p> </p>
<p>to work for some reason. When I made it</p>
<p> </p>
<p>if(params["geoScope"].value.join('/') == "All") true</p>
<p> </p>
<p>It worked. Following your example, my final solution was</p>
<p> </p>
<p>if(params["geoScope"].value.join("/").search("All") > -1) true</p>
<p> </p>
<p>because it is multi-select and if someone selects All as well as another district, I take it 'All' overrules.</p>
<p> </p>
<p>Thanks again.</p>
GLO_FR
<p style="font-size:13.63636302948px;"><span style="font-size:14px;">As I said, the code wasn't tested </span> :unsure:<span style="font-size:14px;"> , but the idea was there !</span></p>
<p style="font-size:13.63636302948px;">Great job mogwai !</p>
Sai krishna
<blockquote class="ipsBlockquote" data-author="mogwai" data-cid="131513" data-time="1413982993">
<div>
<p><span style="font-family:arial, helvetica, sans-serif;"><span style="font-size:14px;">Thanks Guillaume. This works beautifully. I couldn't get </span></span></p>
<p> </p>
<p>if(params["geoScope"].value=="All") true</p>
<p> </p>
<p>to work for some reason. When I made it</p>
<p> </p>
<p>if(params["geoScope"].value.join('/') == "All") true</p>
<p> </p>
<p>It worked. Following your example, my final solution was</p>
<p> </p>
<p>if(params["geoScope"].value.join("/").search("All") > -1) true</p>
<p> </p>
<p>because it is multi-select and if someone selects All as well as another district, I take it 'All' overrules.</p>
<p> </p>
<p>Thanks again.</p>
</div>
</blockquote>
<p> </p>
<blockquote class="ipsBlockquote" data-author="mogwai" data-cid="131513" data-time="1413982993">
<div>
<p><span style="font-family:arial, helvetica, sans-serif;"><span style="font-size:14px;">Thanks Guillaume. This works beautifully. I couldn't get </span></span></p>
<p> </p>
<p>if(params["geoScope"].value=="All") true</p>
<p> </p>
<p>to work for some reason. When I made it</p>
<p> </p>
<p>if(params["geoScope"].value.join('/') == "All") true</p>
<p> </p>
<p>It worked. Following your example, my final solution was</p>
<p> </p>
<p>if(params["geoScope"].value.join("/").search("All") > -1) true</p>
<p> </p>
<p>because it is multi-select and if someone selects All as well as another district, I take it 'All' overrules.</p>
<p> </p>
<p>Thanks again.</p>
</div>
</blockquote>
<p>Hello i too have this same issue. But here instead of Database i am using excel sheet. Could you please help me how to disable the filter when the value was not given to the prompt. Because it was taking the value as null and displaying 0 records</p>