How to print dataGrid selected rows in PDF format

In a view I created a button to print the selected lines in pdf format (simulating the functionality of the excel button).

I followed FREE WEBINARS - REPORTING from 1:11:35 to 1:15:00 and it works perfectly.

DemoPDF.rar (9.2 MB)

<groupTable id="table"
                        multiselect="true"
                        width="100%">
                <actions>
                    <action id="create"/>
                    <action id="edit"/>
                    <action id="remove"/>
                    <action id="excel"/>
                </actions>
                <columns>
                    <column id="attr1"/>
                    <column id="attr2"/>
                    <column id="attr3"/>
                    <column id="attr4"/>
                    <column id="attr5"/>
                </columns>
                <rows datasource="entity1sDs"/>
                <rowsCount/>
                <buttonsPanel id="buttonsPanel"
                              alwaysVisible="true">
                    <button id="createBtn"
                            action="table.create"/>
                    <button id="editBtn"
                            action="table.edit"/>
                    <button id="removeBtn"
                            action="table.remove"/>
                    <button id="excelBtn"
                            action="table.excel"/>
                    <button id="pdfButton"
                            caption="Pdf"
                            icon="FILE_PDF_O"/>
                </buttonsPanel>
            </groupTable>

controller

import com.company.demopdf.entity.Entity1;
import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.EntityCombinedScreen;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.reports.gui.actions.TablePrintFormAction;

import javax.inject.Inject;
import java.util.Map;

public class Entity1Browse extends EntityCombinedScreen {
@Inject
private Button pdfButton;
@Inject
private Table<Entity1> table;

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    pdfButton.setAction(new TablePrintFormAction(table));
}
}

I select 2 of 3 for example

Cattura1

I press pdf button

Cattura2

and report pdf appear

Cattura3

I have a problem, the example above use groupTable, how can I do the same implementation if I have a dataGrid?

There is not “DataGridPrintFormAction()” method :roll_eyes:

Hi,

Could you please attach a zip archive? For that purpose you can use the zipProject gradle task that will compress only project files without tomcat, as the result the file size will be significantly reduced.

Regards,
Gleb

1 Like

DemoPDF.zip (92.9 KB)

You’re right, there is no DataGridPrintFormAction, so I’ve created a GitHub issue. For now, you can easily implement your own using TablePrintFormAction as an example.

Regards,
Gleb

1 Like

I created my DataGridPrintFormAction using TablePrintFormAction as example ant it works.

Thanks

Mauro