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?

有帮助吗?

解决方案 3

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);
}

其他提示

Well... the superclass of ChoiceFilteredPropertyColumn is FilteredPropertyColumn which might do the trick. Otherwise you could always implement your own Column that implements IFilteredColumn the way you like it.

Look at how the implemented `DataTable' here: http://www.packtpub.com/sites/default/files/1605OS-Chapter-5-Displaying-Data-Using-DataTable.pdf

Then you could implement your dropdown button filter like you want it and filter with the selected value the DataTable.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top