Add row if the table row count is 0

zharenkov
edited February 11, 2022 in Analytics #1
<p>Hello,</p>
<p>I've got the report with report parameters startDate and endDate. In some cases the table may be empty(e.g. time period is too short). So in report only headers of the table are shown. I want to add a row in this empty table with message in one cell, e.g. "There is no data for this period" or something like this.</p>
<p>How can I do that?</p>
<p> </p>
<p>I tried to add condition in fetch() script like this</p>
<pre class="_prettyXprint _lang-nocode">
if (totalrows == 0) {
row["serviceName"] = "There is no data";
return(true);
}

if (currentrow >= totalrows) {
return(false);
}

var rowValue = resultInfo.get(currentrow);

row["serviceName"] = rowValue[0];
row["ogvName"] = rowValue[1];
row["ddl"] = rowValue[2];
row["avgTime"] = rowValue[3];
row["countPs"] = rowValue[4];

currentrow = currentrow + 1;

return(true);
</pre>
<p>but it doesn't work. Is any simple solution for this problem?</p>

Comments

  • <p>Hi,</p>
    <p> </p>
    <p>I don't think that the fetch event is the right place because, if you haven't any row in your DS, you will probalbly don't have any fetch.</p>
    <p> </p>
    <p>The easiest way is to to test the rownum and to dynamically set the header.</p>
    <p>When the DS is empty the rownum is -1</p>
    <p> </p>
    <p>Here is a basic example</p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    Warning No formatter is installed for the format ipb
  • <p>Thanks. I added an additional row in my table and set its visiblity like this</p>
    <pre class="_prettyXprint _lang-nocode">
    if(row.__rownum >= 0){
    true
    }else{
    false
    }

    </pre>
    <p>It works fine.</p>
  • <p>Hi,<br><br>
    that's also a way to do it  :)</p>
    Warning No formatter is installed for the format ipb