Export more than one expandable dataTable

Community Driven Extensions Project
Post Reply
Flucero
Posts: 3
Joined: 06 Mar 2019, 12:48

06 Mar 2019, 12:52

Hello,

I was interested in the expandable tables, and they work just fine for me except for one thing. I have 3 tables inside the rowExpansion that represents 3 relations to other tables but when I export to xlsx, it only shows the first table inside the expansion on my file.

Do I need to create my own exporter for this? or is there any way to configure that?.

Thanks for your time.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

07 Mar 2019, 14:03

The Exporter is the one component I am not that familiar with. If you can put together a small sample using this Test project: https://github.com/primefaces/primefaces-test

I can then debug and try and fix it or at least see what is going on!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Flucero
Posts: 3
Joined: 06 Mar 2019, 12:48

07 Mar 2019, 14:30

I ended up with the conclusion that the function exportCells in the ExcelExporter class only gets the first child of the table.

Code: Select all

 if (table.getRowIndex() == 0) {
            for (final UIComponent component : table.getChildren()) {
                if (component instanceof RowExpansion) {
                    final RowExpansion rowExpansion = (RowExpansion) component;
                    if (rowExpansion.getChildren() != null) {
                        if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                            final DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                            childTable.setRowIndex(-1);
                        }
                        if (rowExpansion.getChildren().get(0) instanceof DataList) {
                            final DataList childList = (DataList) rowExpansion.getChildren().get(0);
                            childList.setRowIndex(-1);
                        }
                    }

                }
            }
        }

for (final UIComponent component : table.getChildren()) {
            if (component instanceof RowExpansion) {
                final RowExpansion rowExpansion = (RowExpansion) component;
                if (rowExpansion.getChildren() != null) {
                    if (rowExpansion.getChildren().get(0) instanceof DataList) {
                        final DataList list = (DataList) rowExpansion.getChildren().get(0);
                        if (list.getHeader() != null) {
                            tableFacet(context, sheet, list, "header");
                        }
                        exportAll(context, list, sheet);
                    }
                   if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                        final DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                        final int columnsCount = getColumnsCount(childTable);

                        if (childTable.getHeader() != null) {
                            tableFacet(context, sheet, childTable, columnsCount, "header");

                        }
                        tableColumnGroup(sheet, childTable, "header");

                        addColumnFacets(childTable, sheet, ColumnType.HEADER);

                        exportAll(context, childTable, sheet, false);

                        if (childTable.hasFooterColumn()) {
                            addColumnFacets(childTable, sheet, ColumnType.FOOTER);
                        }
                        tableColumnGroup(sheet, childTable, "footer");
                        childTable.setRowIndex(-1);
                    }

                }
            }
        }
if (rowExpansion.getChildren().get(0) instanceof DataTable) {
final DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);


So now im trying to use the custom exporter feature and override this function to make a loop there.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

07 Mar 2019, 14:32

Let me know if you fix it and i can patch the source code.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Flucero
Posts: 3
Joined: 06 Mar 2019, 12:48

08 Mar 2019, 15:35

Code: Select all


protected void exportCells(final DataTable table, final Sheet sheet) {
        final int sheetRowIndex = sheet.getLastRowNum() + 1;
        final Row row = sheet.createRow(sheetRowIndex);

        facetStyleLeftAlign.setAlignment(HorizontalAlignment.LEFT);
        facetStyleCenterAlign.setAlignment(HorizontalAlignment.CENTER);
        facetStyleCenterAlign.setVerticalAlignment(VerticalAlignment.CENTER);
        facetStyleCenterAlign.setWrapText(true);
        facetStyleRightAlign.setAlignment(HorizontalAlignment.RIGHT);
        cellStyleLeftAlign.setAlignment(HorizontalAlignment.LEFT);
        cellStyleCenterAlign.setAlignment(HorizontalAlignment.CENTER);
        cellStyleRightAlign.setAlignment(HorizontalAlignment.RIGHT);

        for (final UIColumn col : table.getColumns()) {

            if (col instanceof DynamicColumn) {
                ((DynamicColumn) col).applyStatelessModel();
            }

            if (col.isRendered() && col.isExportable()) {
                addColumnValue(row, col.getChildren(), "content", col);
            }
        }
        final FacesContext context = null;
        if (table.getRowIndex() == 0) {
            for (final UIComponent component : table.getChildren()) {
                if (component instanceof RowExpansion) {
                    final RowExpansion rowExpansion = (RowExpansion) component;
                    if (rowExpansion.getChildren() != null) {
                        if (rowExpansion.getChildren().get(0) instanceof DataTable) {
                            final DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
                            childTable.setRowIndex(-1);
                        }
                        if (rowExpansion.getChildren().get(0) instanceof DataList) {
                            final DataList childList = (DataList) rowExpansion.getChildren().get(0);
                            childList.setRowIndex(-1);
                        }
                    }

                }
            }
        }
        for (final UIComponent component : table.getChildren()) {
            if (component instanceof RowExpansion) {
                final RowExpansion rowExpansion = (RowExpansion) component;
                if (rowExpansion.getChildren() != null) {
                	for (int i = 0; i < rowExpansion.getChildren().size(); i++) {
	                    if (rowExpansion.getChildren().get(i) instanceof DataList) {
	                        final DataList list = (DataList) rowExpansion.getChildren().get(i);
	                        if (list.getHeader() != null) {
	                            tableFacet(context, sheet, list, "header");
	                        }
	                        exportAll(context, list, sheet);
	                    }
                	}
                    for (int i = 0; i < rowExpansion.getChildren().size(); i++) {
	                    if (rowExpansion.getChildren().get(i) instanceof DataTable) {
	                        final DataTable childTable = (DataTable) rowExpansion.getChildren().get(i);
	                        final int columnsCount = getColumnsCount(childTable);
	                        if (columnsCount > 0) { // In case none of the colums are exportable.
		                        if (childTable.getHeader() != null) {
		                            tableFacet(context, sheet, childTable, columnsCount, "header");
		
		                        }
		                        tableColumnGroup(sheet, childTable, "header");
		
		                        addColumnFacets(childTable, sheet, ColumnType.HEADER);
		
		                        exportAll(context, childTable, sheet, false);
		
		                        if (childTable.hasFooterColumn()) {
		                            addColumnFacets(childTable, sheet, ColumnType.FOOTER);
		                        }
		                        tableColumnGroup(sheet, childTable, "footer");
		                        childTable.setRowIndex(-1);
	                        }
	                    }
                    }

                }
            }
        }
    }

The loop < for (int i = 0; i < rowExpansion.getChildren().size(); i++) { .. } fixes the problem.

Notice I also put an extra if <if (columnsCount > 0) { // In case none of the colums are exportable.> because the tag rowExpasion do not have the attribute exportable and I made a function to let the user chose what extra tables related to the main one export. So I have a dynamic exportable="#{bean.boolean}" on each column of each expandable table.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

08 Mar 2019, 16:02

I reported it here: https://github.com/primefaces-extension ... issues/662

And I fixed it, it will be in the 7.0 Release to go with PF 7.0.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests