Is there a cookbook for adding an export to excel on a default table browser view?

I just got started with Cuba Platform and I am looking for some cookbooks.

For example, how to add an export to excel button on a page.

I have queried here and mostly it’s people asking for enhancements.

Say I have a simple table, create the default browser view and want a button to export to excel.

Hi,

https://doc.cuba-platform.com/manual-6.8/list_actions.html#excelAction

Bye

I’m afraid the documentation does not give practical instructions in this part.

As long as “Excel export” is a standard built-in action, you can add it to the screen declaratively. Open the actions editor for the table, and add an action with excel identifier:
image

Then add a button and set the action for it.

In XML, it looks as follows:

<groupTable>
    <actions>
        <!-- ... -->
        <action id="excel"/>
    </actions>
    <!-- ... -->
    <buttonsPanel>
        <!-- ... -->
        <button action="barsTable.excel"/>
    </buttonsPanel>
</groupTable>

Cuba Platform

Excel Support

Steps

As long as “Excel export” is a standard built-in action, you can add it
to the screen declaratively. Open the actions editor for the table, and
add an action with excel identifier:

  • On the left side of Cuba Studio click on Generic UI
  • Scroll down to your entity
  • Select the xml associate with the view

Naming, the database table all lower case with underscores replaced by
hyphens followed by “-browse.xml”

This opens Screen Designer with the tabs * Properties * Layout
* Datasources * xml * controller

Where is this Actions Editor?

Under the XML tab

The xml file in this case is in

./modules/web/src/com/pds/pdssr/web/saleproductcustvw/sale-product-cust-vw-browse.xml

${PROJECT_ROOT}/modules/web/src/${PROJECT_PACKAGE}/web/saleproductcustvw/sale-product-cust-vw-browse.xml

After editting it looks like this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://browseCaption"
        class="com.pds.pdssr.web.saleproductcustvw.SaleProductCustVwBrowse"
        focusComponent="saleProductCustVwsTable"
        lookupComponent="saleProductCustVwsTable"
        messagesPack="com.pds.pdssr.web.saleproductcustvw">
    <dsContext>
        <groupDatasource id="saleProductCustVwsDs"
                         class="com.pds.pdssr.entity.SaleProductCustVw"
                         view="_local">
            <query>
                <![CDATA[select e from pdssr$SaleProductCustVw e]]>
            </query>
        </groupDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="saleProductCustVwsTable"
            spacing="true">
        <filter id="filter"
                applyTo="saleProductCustVwsTable"
                datasource="saleProductCustVwsDs">
            <properties include=".*"/>
        </filter>
        <groupTable id="saleProductCustVwsTable"
                    width="100%">
            <actions>
                <action id="create"/>
                <action id="edit"/>
                <action id="remove"/>
            </actions>
            <columns>
                <column id="orgDistrib"/>
                <column id="orgMfr"/>
                <column id="product"/>
                <column id="distributorCustomer"/>
                <column id="invAmt"/>
                <column id="caseEquivQty"/>
                <column id="itemQty"/>
                <column id="invDt"/>
                <column id="productDescr"/>
            </columns>
            <rows datasource="saleProductCustVwsDs"/>
            <rowsCount/>
            <buttonsPanel id="buttonsPanel"
                          alwaysVisible="true">
                <button id="createBtn"
                        action="saleProductCustVwsTable.create"/>
                <button id="editBtn"
                        action="saleProductCustVwsTable.edit"/>
                <button id="removeBtn"
                        action="saleProductCustVwsTable.remove"/>
                <button action="saleProductCustVwsTable.excel"/>
            </buttonsPanel>
        </groupTable>
    </layout>
</window>

Note the relevant entry is:

  <button action="saleProductCustVwsTable.excel"/>}

The directory name is the database table name, all lower case with “_“
removed. The file name is the database table name with “_” replaced by
”-”

In Cuba Studio

  1. Build -> Assemble Project
  2. Run -> Restart Application Server

I now get the following error:

GuiDevelopmentException: Can't find action 'excel' in 'saleProductCustVwsTable'

Frame ID: pdssr$SaleProductCustVw.browse
XML descriptor: com/pds/pdssr/web/saleproductcustvw/sale-product-cust-vw-browse.xml
Holder ID: saleProductCustVwsTable

Questions

What is the actions editor for a table?

Google “cuba platform actions editor”

References

https://www.google.com/search?q=cuba+platform+actions+editor

https://doc.cuba-platform.com/manual-6.4/declarative_actions.html

Questions

What is the actions editor for a table?

What changes do I make to my code to support this xml change?

Under actions there must be an action:

 <actions>
            <action id="create"/>
            <action id="edit"/>
            <action id="remove"/>
            <action id="excel"/>
 </actions>

There must also be a button:

        <buttonsPanel id="buttonsPanel"
                      alwaysVisible="true">
            <button id="createBtn"
                    action="saleProductCustVwsTable.create"/>
            <button id="editBtn"
                    action="saleProductCustVwsTable.edit"/>
            <button id="removeBtn"
                    action="saleProductCustVwsTable.remove"/>
            <button id="excelBtn"
                    action="saleProductCustVwsTable.excel"/>
        </buttonsPanel>

That’s all there is to it, I found the demo:

As for the Actions editor, it’s here:

image

I never would have found that.

That also answered a different question as I didn’t know how to name an event.