zhoupan / jmesa

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

Add new filter without show the column #240

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to add a new filter in my jmesa, but really I don't now if I can
do it. All columns I show can be filtered if I write "<jmesa:htmlColumn
property='prioridad' filterable='true'......". My question is if it's
necessary I show a field to filter it, or if I can filter a field I don´t
want to show.

I've made a class I use in the tablefacade
(rowFilter="es.opencms.jmesa.filtros.CustomSimpleRowFilter"), but the
filter doesn't show in my JMESA. It only show the filters connected to the
columns:
<jmesa:tableFacade toolbar="es.opencms.jmesa.ToolbarJMesa"
id="jmesa_noticias" stateAttr="restore" maxRows="5" 
maxRowsIncrements="5,10,15" items="${listado}" var="noticias"
editable="true" exportTypes="jexcel,pdfp,csv" 
rowFilter="es.opencms.jmesa.filtros.CustomSimpleRowFilter">
    <jmesa:htmlTable>
        <jmesa:htmlRow uniqueProperty="id">
            <jmesa:htmlColumn property="checkbox" title="${checks}"
editable="true"
worksheetEditor="org.jmesa.worksheet.editor.CheckboxWorksheetEditor"
filterable="false" sortable="false" width="2%"/>
            <jmesa:htmlColumn property="fecha" title="Fecha"
pattern="dd/MM/yyyy" editable="false"
cellEditor="org.jmesa.view.editor.DateCellEditor" sortable="true"
width="10%" headerClass="sortable" sortOrder="asc,desc,none"  />
            <jmesa:htmlColumn property="titular"
cellEditor="es.opencms.jmesa.ficha.FilaNoticiaPinchada" title="Titular"
sortable="true" editable="false" headerClass="sortable"
sortOrder="asc,desc,none" width="70%"/>
            <jmesa:htmlColumn property="prioridad" filterable="true"
title="Prioridad" editable="false" sortable="true" headerClass="sortable"
sortOrder="desc,asc,none" width="8%"/>
            <jmesa:htmlColumn property="nombreFichero"
title="NombreFichero" sortable="true" editable="false"
headerClass="sortable" sortOrder="asc,desc,none" width="30%"/>
            <jmesa:htmlColumn property="visible" title="Visible"
editable="false" sortable="true" width="10%"
filterEditor="es.opencms.jmesa.filtros.FiltroBooleano"><img
src="<cms:link>${rutaImagen}dibujos/${noticias.mostrarVisible}</cms:link>"
/></jmesa:htmlColumn> 
        </jmesa:htmlRow>
    </jmesa:htmlTable>
</jmesa:tableFacade>

The code of that class:
public class CustomSimpleRowFilter extends SimpleRowFilter {

    @Override
    protected Map<Filter, FilterMatcher> getFilterMatchers(Collection<?>
items, FilterSet filterSet) {
        Map<Filter, FilterMatcher> filterMatchers = new HashMap<Filter,
FilterMatcher>();

        FilterMatcherRegistry registry = getFilterMatcherRegistry();

        // insert custom code
        if (items == null || !items.iterator().hasNext()) {
            return filterMatchers;
        }

        try {
            for (Filter filter : filterSet.getFilters()) {
                String property = "fileName";
                Class<?> type = getPropertyClassType(items, property);
                MatcherKey key = new MatcherKey(type, property);
                FilterMatcher filterMatcher = registry.getFilterMatcher(key);
                filterMatchers.put(filter, filterMatcher);
            }
        } catch (Exception e) {
            System.out.println("**ERROR: No se ha podido filtrar por la
propiedad 'nombreFichero'. -- " + e.getMessage());
        }

        return filterMatchers;

    }
}

Maybe my way isn't right. Maybe it isn't possible to do. Maybe I'm too
beginner (well, really i'm sure) :D

Original issue reported on code.google.com by andyned...@gmail.com on 13 Jan 2010 at 8:25

GoogleCodeExporter commented 9 years ago
The filtering is not really connected to the view (by design). If you set the 
value on the Limit then it would be filtered.

Original comment by jeff.johnston.mn@gmail.com on 10 Mar 2011 at 10:07