YARG - Print a band if it has data only

Hi,

I would like to know if this is possible to add a logic in the report template in order to display a band if it has data only.
In my case I have several tables in a docx template file each of them in a separate band so I want to display only the ones that have data.

Thank you,

Gyo

cs.docx (7.8K)

Hello.

For now the only way to hide the whole table (or any other content) is to put it to another table (invisible), with one cell, and link the wrapping table with a band which will have date only if the nested table has data.

It’s not obvious, so I will try to provide you an example of how to do it right.

Also I will include the option to hide empty tables to the backlog.

I have also the same problem, please provide an example

Hello.

Please see the following template .

There “Control1” band should have 1 row if the embedded table should be shown or no rows if the embedded table should be hidden.

Unfortunately, for now that’s the only way to hide content in DOCX templates.
Also, you should note that the above way has been broken in previous releases, and has been fixed in YARG’s master branch. We wll release the fix ASAP.

Thank you for you feedback.

Hi Eugene,

thanks a lot for you feedback. Another question: What should I put in the xml file?

Thank you

Hello.

The xml should be like the following, you should return null in Control1 band if you don’t need to show the tabe and return the list with 1 element if you need to show it.

It should work in next YARG release - 1.0.61, or you can build YARG from master branch. You also will have to set cuba.reporting.dataextractor.putEmptyRowIfNoDataSelected to false.


<report name="report">
    <templates>
        <template code="DEFAULT" documentName="console2.docx" documentPath="./modules/core/test/console/console2.docx" outputType="docx"
                  outputNamePattern="outputNamePattern"></template>
    </templates>
    <parameters>
    </parameters>
    <formats></formats>
    <rootBand name="Root" orientation="H">
        <bands>
            <band name="Band1" orientation="H">
                <bands></bands>
                <queries>
                    <query name="Data_set_1" type="groovy">
                        <script>return [['value1':'1', 'value2':'2'], ['value1':'3', 'value2':'4']]</script>
                    </query>
                </queries>
            </band>
            <band name="Control1" orientation="H">
                <bands></bands>
                <queries>
                    <query name="Data_set_1" type="groovy">
                        <script>return null</script>
                    </query>
                </queries>
            </band>
        </bands>
        <queries></queries>
    </rootBand>
</report>

<report name="report">
    <templates>
        <template code="DEFAULT" documentName="console2.docx" documentPath="./modules/core/test/console/console2.docx" outputType="docx"
                  outputNamePattern="outputNamePattern"></template>
    </templates>
    <parameters>
    </parameters>
    <formats></formats>
    <rootBand name="Root" orientation="H">
        <bands>
            <band name="Band1" orientation="H">
                <bands></bands>
                <queries>
                    <query name="Data_set_1" type="groovy">
                        <script>return [['value1':'1', 'value2':'2'], ['value1':'3', 'value2':'4']]</script>
                    </query>
                </queries>
            </band>
            <band name="Control1" orientation="H">
                <bands></bands>
                <queries>
                    <query name="Data_set_1" type="groovy">
                        <script>return [['flag':true]]</script>
                    </query>
                </queries>
            </band>
        </bands>
        <queries></queries>
    </rootBand>
</report>