wanjidong / jmesa

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

Contribution: set column properties easily #196

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Here is another little contribution that I use very often (in all my
tables). And it shows also another little problem that I found when
exporting my tables.
It is a method to set the params of a column (title, filterable, sortable,
editable) in an easy way. I have it in some util class but in case it is
admisible for jmesa it should go, I guess, in the Table or Row
implementations (but look out for the export problem I'll explain at the
end of the post)

This is it:

    public static void setColumnParams(Table table, String property, String
title, boolean filterable, boolean sortable, boolean editable) {

        if (table instanceof HtmlTable) {
            HtmlRow htmlRow = ((HtmlTable)table).getRow();
            HtmlColumn htmlColumn = htmlRow.getColumn(property);
            htmlColumn.setTitle(title);
            htmlColumn.setFilterable(new Boolean(filterable));
            htmlColumn.setSortable(new Boolean(sortable));
            htmlColumn.setEditable(new Boolean(editable));
        }
        else if(table instanceof TableImpl){
            Row row =((TableImpl)table).getRow();       
            Column column = row.getColumn(property);
            column.setTitle(title);         
        }

    }

I usually create my methods so they can be used when rendering the html and
when exporting (I like to set the title of the column in both cases or do
strange things with the values as well). This leads to a little problem:
When exporting to EXCEL the table is not an instance of HtmlTable, which is
correct because it is meaningless to render html or to make the column
filterable, sortable, ... when making an Excel. But it's not the case when
exporting to PDF (or while rendering the html, of course).
This makes that if you want to do something with a column that will show up
in both cases (html and export) you have always to check the class type of
the table or you will be facing some "pretty" ClassCastExceptions...

The same way I can set a column with my CheckBoxCellEditor (see the Issue
for that contribution) before the code that makes the export so it can
apply to render html and exporting.
I hope I made myself clear and haven't been too boring... hehe
(and by the way, I'm always sorry if my english is not perfect...)

Cheers,
Alex

Original issue reported on code.google.com by AlejaV...@gmail.com on 14 May 2009 at 7:35

GoogleCodeExporter commented 8 years ago
You know what would be interesting would be to use the builder pattern. The 
pattern
would works perfect even though it would be to populate the object. Even the 
renderer
methods could be exposed through the builder. The great thing is how easy it is 
to
read and work with.

Something like this:

ColumnPopulator populator = new ColumnPopulator(TableFacade tableFacade, String
columnName);
populator.filterable(false).sortable(false).editable(true).cellEditor(myCellEdit
or);

Original comment by jeff.johnston.mn@gmail.com on 15 May 2009 at 9:41

GoogleCodeExporter commented 8 years ago
how can i sum a whole column? 

how can i group columns?    

Original comment by danniv21@gmail.com on 19 May 2009 at 9:59

GoogleCodeExporter commented 8 years ago
To group and total columns you need to create a custom view. Its a little 
involved
but not too difficult once you get the hang of it. It is very powerful though 
and
allows you to tweak the view however you want!

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

Original comment by jeff.johnston.mn@gmail.com on 20 May 2009 at 2:43

GoogleCodeExporter commented 8 years ago

Original comment by jeff.johnston.mn@gmail.com on 11 Jun 2009 at 12:52