Search code examples
buttondatatablewicketchoicefielddropdownchoice

Wicket custom filter without dropdown table


I want to create a custom filter for my DataTable. I would like to create a button that, when clicked on it, changes the table its data. I know about the ChoiceFilteredPropertyColumn that wicket has to offer but this is, according to my understanding of it, a dropdown filter.

I am trying to achieve something like the following picture (Pancakes is the clickable button): example data table clickable button

Could someone point me in the right direction?


Solution

  • I solved this question by creating a custom filter (just a panel with some markup) and return it in the getFilter method of a custom FilteredPropertyColumn.

    FilteredPropertyColumn: http://wicket.apache.org/apidocs/1.4/org/apache/wicket/extensions/markup/html/repeater/data/table/filter/FilteredPropertyColumn.html

    getFilter method: http://wicket.apache.org/apidocs/1.4/org/apache/wicket/extensions/markup/html/repeater/data/table/filter/IFilteredColumn.html#getFilter%28java.lang.String,%20org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm%29

    ButtonFilter class:

    public class ButtonFilter extends Panel {
         ...
    }
    

    In custom FilteredPropertyColumn class:

    @Override
    public Component getFilter(String componentId, FilterForm<?> form) {
        return new ButtonFilter<Y>(componentId, getFilterModel(form), filterChoices);
    }