homena / jmesa

Automatically exported from code.google.com/p/jmesa
0 stars 0 forks source link

Export only some columns #254

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi!! I've a problem, and it's I can't export the columns I would like. My
JMesa show 4 columns (checkbox, date, headline and a priority number):

TableFacade tablefacade =
TableFacadeFactory.createTableFacade("jmesa_noticias", request);
tablefacade.setEditable(true);
tablefacade.setColumnProperties("checkbox", "fecha", "titular", "prioridad");
tablefacade.setItems(listado);
tablefacade.setExportTypes(response, ExportType.CSV,ExportType.JEXCEL,
ExportType.PDFP);
tablefacade.setStateAttr("restore");

BotonesJMesa botones = new BotonesJMesa();
botones.setGrupoAltaBajas(true);

BarraDeHerramientas toolbar = new BarraDeHerramientas();
toolbar.setBotones(botones);
tablefacade.setToolbar(toolbar);

HtmlComponentFactory factory = new
HtmlComponentFactory(tablefacade.getWebContext(),
tablefacade.getCoreContext());
HtmlTable table = factory.createTable();
HtmlRow row = factory.createRow();
row.setUniqueProperty("id"); 

HtmlColumn colCheck = factory.createColumn("checkbox");
colCheck.setTitle("<input type=\"checkbox\"
onclick=\"selectAllItems('jmesa_noticias')\"/>");
colCheck.getCellRenderer().setWorksheetEditor(new CheckboxWorksheetEditor());
colCheck.setFilterable(false);
colCheck.setSortable(false);

HtmlColumn colFecha = factory.createColumn("fecha");
colFecha.setTitle("Fecha");
colFecha.setEditable(false);
colFecha.getCellRenderer().setCellEditor(new DateCellEditor("dd/MM/yyyy"));

HtmlColumn colTitular = factory.createColumn("titular");
colTitular.setTitle("Titular");
colTitular.setEditable(false);
colTitular.setProperty("titular");

HtmlColumn colPrioridad = factory.createColumn("prioridad");
colPrioridad.setTitle("Prioridad");
colPrioridad.setEditable(false);
colPrioridad.setProperty("prioridad");

row.addColumn(colCheck);
row.addColumn(colFecha);
row.addColumn(colTitular);
row.addColumn(colPrioridad);

table.setRow(row); // be sure to set the row on the table

tablefacade.setTable(table);

Limit limit = tablefacade.getLimit();

if (limit.isExported()) {
    tablefacade.render();
} else {
    String html = tableFacade.render();
}

-----------------------

If I export it, the PDF document show the first column with the checkbox
code. I would like export the other columns, but not checkbox. I need the
checkbox column, but not in a PDF or Excel document.

Thanks so much!! ;)

Original issue reported on code.google.com by andyned...@gmail.com on 10 Mar 2010 at 11:39

GoogleCodeExporter commented 9 years ago
You should move your check of the limit.isExported() before you work with the 
table
and set the column properties based on whether or not you are doing an export.

Also, if you call the tablefacade.setColumnProperties() then you do not have to 
build
the table with the HtmlComponentFactory. Just pull the table from the 
tableFacade,
which builds the table, and then modify the row and columns as needed. Try 
looking at
the basic example for more information.

http://code.google.com/p/jmesa/wiki/BasicTutorial

There is really nothing wrong with building using the HtmlComponentFactory. It 
is
just not necessary when you set the column properties ahead of time.

Or, you might want to try using the new builder class.

http://code.google.com/p/jmesa/wiki/HtmlTableBuilder

Original comment by jeff.johnston.mn@gmail.com on 11 Mar 2010 at 2:52

GoogleCodeExporter commented 9 years ago
Thanks for you response!!

I've followed your indications and it's OK!! ;) I've a new problem to export. 
Export
to PDF is OK, but if I export to CSV or Excel, the cell with the information 
show it:
"[td]....value1...[/td]" "[td]....value1...[/td]" (I don't use '<' because 
visually
it can't modify this post ;D).
So I found this reference: http://code.google.com/p/jmesa/wiki/Exports
My problem is JMesa2.4.6 don`t exist ExcelComponentFactory. With 
CsvComponentFactory
isn´t problem (the CSV export is right), but with Excel... This is my code:

if (limit.isExported()) {
    if (limit.getExportType() == ExportType.JEXCEL) {
        ExcelComponentFactory factoryExcel = new
ExcelComponentFactory(tablefacade.getWebContext(), 
tablefacade.getCoreContext());

        Table table = factoryExcel.createTable();

        Row row = factoryExcel.createRow();
        Column col = factoryExcel.createColumn("fecha");
        col.getCellRenderer().setCellEditor(new DateCellEditor("dd/MM/yyyy"));
        row.addColumn(col);
        col = factoryExcel.createColumn("titular");
        row.addColumn(col);
        col = factoryExcel.createColumn("prioridad");
        row.addColumn(col);

        table.setRow(row); // be sure to set the row on the table

        tablefacade.setTable(table);
  }else if (limit.getExportType() == ExportType.CSV) {
        CsvComponentFactory factoryCsv = new
CsvComponentFactory(tablefacade.getWebContext(), tablefacade.getCoreContext());

        Table table = factoryCsv.createTable();

        Row row = factoryCsv.createRow();
        Column col = factoryCsv.createColumn("fecha");
        col.getCellRenderer().setCellEditor(new DateCellEditor("dd/MM/yyyy"));
        row.addColumn(col);
        col = factoryCsv.createColumn("titular");
        row.addColumn(col);
        col = factoryCsv.createColumn("prioridad");
        row.addColumn(col);

        table.setRow(row); // be sure to set the row on the table

        tablefacade.setTable(table);
    }else{                   
                HtmlComponentFactory factory = new
HtmlComponentFactory(tablefacade.getWebContext(), tablefacade.getCoreContext());
        Table table = factory.createTable();

        Row row = factory.createRow();
        HtmlColumn col = factory.createColumn("fecha");
        col.setEditable(false);
        col.getCellRenderer().setCellEditor(new DateCellEditor("dd/MM/yyyy"));
        row.addColumn(col);
        col = factory.createColumn("titular");
        col.setEditable(false);
        row.addColumn(col);
        col = factory.createColumn("prioridad");
        col.setEditable(false);
        row.addColumn(col);

        table.setRow(row); // be sure to set the row on the table

        tablefacade.setTable(table);
    }

    tablefacade.render();

} else {
    .....
}

--------------

Excel exporting with HtmlComponentFactory is wrong too. ARRRRGGHH!! :D Any 
idea??

Thanks for your time and patience :D

Original comment by andyned...@gmail.com on 11 Mar 2010 at 8:11

GoogleCodeExporter commented 9 years ago
Well... I changed my heavy code to this one, and it's all right for ever and 
ever!! :D
if (limit.isExported()) {
   tablefacade.setColumnProperties("fecha", "titular", "prioridad");
   Table table = tablefacade.getTable();
   table.setCaption("Noticias");
   Row row = table.getRow();
   Column fecha = row.getColumn("fecha");
   fecha.getCellRenderer().setCellEditor(new DateCellEditor("dd/MM/yyyy"));
   tablefacade.render();
} else { ... }

Thanks so much!! I see you in another "ISSUES" XD

Original comment by andyned...@gmail.com on 11 Mar 2010 at 10:00

GoogleCodeExporter commented 9 years ago

Original comment by jeff.johnston.mn@gmail.com on 13 Apr 2010 at 7:04