Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
pagebreak depending on the data retrieved from the table
pratikgala
<p>There is a case when either of the table grows and I want to that page to break when the total rows of the both the table accumulate grows beyond a certain point eg. 40.</p>
<p> </p>
<p>Each page is designed as a grid </p>
<p>Grid1 has two tables:</p>
<div> </div>
<div>Table 1: I click on the table and go to the onCreate of script tab.</div>
<div> </div>
<div>table1 =this.getRowData().getExpressionValue('row[count]');</div>
<div>reportContext.setPersistentGlobalVariable("table1", table1);</div>
<div> </div>
<div>Table 2: I click on the table and go to the onCreate of script tab.</div>
<div> </div>
<div>
<div>table2 = this.getRowData().getExpressionValue('row[count1]');</div>
<div>reportContext.setPersistentGlobalVariable("table2", table2);</div>
<div>table1 = reportContext.getPersistentGlobalVariable("table1");</div>
<div>sum = table1 + table2;</div>
<div>if(sum > 30){</div>
<div>this.getStyle().pageBreakBefore = "always";</div>
<div>}</div>
</div>
<p> </p>
Find more posts tagged with
Comments
JFreeman
<p>I'm not clear on exactly what you are asking.</p>
<p>Could you please provide additional details about what you want to do and the issue you are running into?</p>
pratikgala
<blockquote class="ipsBlockquote" data-author="JFreeman" data-cid="136877" data-time="1433793528">
<div>
<p>I'm not clear on exactly what you are asking.</p>
<p>Could you please provide additional details about what you want to do and the issue you are running into?</p>
</div>
</blockquote>
<p>So I have grid with two tables inside it.</p>
<p>At a certain condition I want one of the table to break and get it displayed on the other page.</p>
<p> </p>
<p>The condition is supposed to be link this. </p>
<p> </p>
<p>totalTable1 = get total row count of table 1</p>
<p>totalTable2 = get total row count of table 2</p>
<p> </p>
<p>add = totalTable1 + totalTable2;</p>
<p> </p>
<p>if(add > 40){</p>
<p> pagebreak always at table2 header; </p>
<p>}</p>
<p> </p>
<p>// if you could tell me the exact syntax of how to retrieve a table cell value and syntax for page break at header of // table in the onCreate script that would be helpful.</p>
JFreeman
<p>I'm still not clear on what your full desired behavior is.</p>
<p> </p>
<p>Let's say table 1 gets 100 rows and table 2 gets 80 rows.</p>
<p>In this scenario, how are you wanting the output to look?</p>
pratikgala
<blockquote class="ipsBlockquote" data-author="JFreeman" data-cid="136921" data-time="1433867114">
<div>
<p>I'm still not clear on what your full desired behavior is.</p>
<p> </p>
<p>Let's say table 1 gets 100 rows and table 2 gets 80 rows.</p>
<p>In this scenario, how are you wanting the output to look?</p>
</div>
</blockquote>
<p>if(sum > 30){</p>
<p> page break on table 2.</p>
<p>}</p>
<p> </p>
<p>sum is the total count of rows of table 1 and table 2</p>
pratikgala
<blockquote class="ipsBlockquote" data-author="pratikgala" data-cid="136922" data-time="1433867216">
<div>
<p>if(sum > 30){</p>
<p> page break on table 2.</p>
<p>}</p>
</div>
</blockquote>
<p>sum is the total count of rows of table 1 and table 2</p>
JFreeman
<p>So in that scenario, your page break interval on table 1 is set to the default of 40?</p>
<p>Then you would have table one display 40 rows on page 1 and 2 and 20 rows on page 3 then break before displaying table 2 starting on page 4.</p>
<p> </p>
<p>However, if table 1 has 10 rows and table 2 has 15 rows you want both tables to be displayed on the same page.</p>
<p> </p>
<p>Is that what you are wanting?</p>
pratikgala
<blockquote class="ipsBlockquote" data-author="JFreeman" data-cid="136930" data-time="1433872186">
<div>
<p>So in that scenario, your page break interval on table 1 is set to the default of 40?</p>
<p>Then you would have table one display 40 rows on page 1 and 2 and 20 rows on page 3 then break before displaying table 2 starting on page 4.</p>
<p> </p>
<p>However, if table 1 has 10 rows and table 2 has 15 rows you want both tables to be displayed on the same page.</p>
<p> </p>
<p>Is that what you are wanting?</p>
</div>
</blockquote>
<p>yes thats correct. </p>
<p> </p>
<p>I am finding it hard to write the code. <br>
Heres what I have tried. </p>
<p>in the oncreate script of table 1: <br>
</p>
<div>table1 =row;</div>
<div>reportContext.setPersistentGlobalVariable("table1", table1);</div>
<div> </div>
<div>in the onCreate script of table 2: </div>
<div> </div>
<div>
<div>table2 = row;</div>
<div>table1 = reportContext.getPersistentGlobalVariable("table1");</div>
<div>sum = table1 + table2;</div>
<div>if(sum > 10){</div>
<div> this.getStyle().pageBreakBefore = "Always";</div>
<div>}</div>
</div>
JFreeman
<p>Are row["count"] and row["count1"] coming from a computed column in your data sets?</p>
pratikgala
<blockquote class="ipsBlockquote" data-author="JFreeman" data-cid="136932" data-time="1433878309">
<div>
<p>Are row["count"] and row["count1"] coming from a computed column in your data sets?</p>
</div>
</blockquote>
<p>yes they are compute columns. but we can ignore that if there is a way to get the row count from the script itself </p>
JFreeman
<p>Instead of using computed columns, you can set the count global variables during the onFetch of the data set and then grab them in the onCreate of the second table. I just did it this way and the page break change is working as I described above.</p>
<p> </p>
<p>onFetch of Data Set 1:</p>
<pre class="_prettyXprint _lang-js">
var count = reportContext.getPersistentGlobalVariable("count1");
if(!count){
reportContext.setPersistentGlobalVariable("count1", "1");
}else if(count){
count = (parseInt(count) + 1).toString();
reportContext.setPersistentGlobalVariable("count1", count);
}
</pre>
<p>onFetch of Data Set 2:</p>
<pre class="_prettyXprint _lang-js">
var count2 = reportContext.getPersistentGlobalVariable("count2");
if(!count2){
reportContext.setPersistentGlobalVariable("count2", "1");
}else if(count2){
count2 = (parseInt(count2) + 1).toString();
reportContext.setPersistentGlobalVariable("count2", count2);
}
</pre>
<p>onCreate of table 2:</p>
<pre class="_prettyXprint _lang-js">
var count1 = reportContext.getPersistentGlobalVariable("count1");
var count2 = reportContext.getPersistentGlobalVariable("count2");
var totalCount = parseInt(count1) + parseInt(count2);
if(totalCount > 40){
this.getStyle().pageBreakBefore = "always";
}
</pre>
pratikgala
<blockquote class="ipsBlockquote" data-author="JFreeman" data-cid="136939" data-time="1433882865">
<div>
<p> </p>
<p>Instead of using computed columns, you can set the count global variables during the onFetch of the data set and then grab them in the onCreate of the second table. I just did it this way and the page break change is working as I described above.</p>
<p> </p>
<p>onFetch of Data Set 1:</p>
<pre class="_prettyXprint _lang-js">
var count = reportContext.getPersistentGlobalVariable("count1");
if(!count){
reportContext.setPersistentGlobalVariable("count1", "1");
}else if(count){
count = (parseInt(count) + 1).toString();
reportContext.setPersistentGlobalVariable("count1", count);
}
</pre>
<p>onFetch of Data Set 2:</p>
<pre class="_prettyXprint _lang-js">
var count2 = reportContext.getPersistentGlobalVariable("count2");
if(!count2){
reportContext.setPersistentGlobalVariable("count2", "1");
}else if(count2){
count2 = (parseInt(count2) + 1).toString();
reportContext.setPersistentGlobalVariable("count2", count2);
}
</pre>
<p>onCreate of table 2:</p>
<pre class="_prettyXprint _lang-js">
var count1 = reportContext.getPersistentGlobalVariable("count1");
var count2 = reportContext.getPersistentGlobalVariable("count2");
var totalCount = parseInt(count1) + parseInt(count2);
if(totalCount > 40){
this.getStyle().pageBreakBefore = "always";
}
</pre>
</div>
</blockquote>
<p>thank you for the response. </p>
<p>This is solved .</p>
<p> </p>
<p> </p>
<p>I did some changes and heres what I tried : </p>
<p> </p>
<p>onCreate of table1: </p>
<div>var val = this.getRowData().getExpressionValue("row[Aggregation_1]");</div>
<div>reportContext.setPersistentGlobalVariable("totRowCountTbl1", val);</div>
<div>log(" tbl1 : "+val);</div>
<div> </div>
<div>onCreate of table2:</div>
<div>
<div> </div>
<div>var totRowCountFromTbl1 = reportContext.getPersistentGlobalVariable("totRowCountTbl1");</div>
<div>log(" totRowCountFromTbl1 : "+totRowCountFromTbl1);</div>
<div> </div>
<div>var totRowCountFromtbl2 = this.getRowData().getExpressionValue("row[Aggregation_1]");</div>
<div>log(" totRowCountFromtbl2 : "+totRowCountFromtbl2);</div>
<div> </div>
<div>if(totRowCountFromTbl1 != 0){</div>
<div> if(totRowCountFromtbl2 != 0){</div>
<div> var sum = parseInt(totRowCountFromTbl1) + parseInt(totRowCountFromtbl2);</div>
<div> if((sum >= 34) && (totRowCountFromTbl1 <= 33 )){</div>
<div> this.getStyle().pageBreakBefore = "Always";</div>
<div> }</div>
<div> }</div>
<div>}</div>
<div> </div>
</div>
JFreeman
<p>You're welcome.</p>
<p>I'm glad to hear you were able to get it solved.</p>
<p> </p>
<p>Let us know if you have additional questions.</p>