Le mercredi 15 avril 2009 à 20:02 +0300, Serkan Camurcuoglu a écrit : > sorry for my previous post.. what i've previously done is: > > - add a filtertoolbar to your datatable > - make some of your columns IFilteredColumn, for example I've used > TextFilteredPropertyColumn but there are also others > - make your dataprovider implement IFilterStateLocator > - implement the filtering logic by checking the current state of the > filter in your iterator method > - no need to change html > > I'm not sure if that's the best way to do it, but it may help you get > started.. Thx for your help!
I'am currently trying to figure how to use TextFilteredPropertyColumn and what model he needs. my dataProvider is a list of, say, Incident with firstName, lastName, and age My non filtered columns are : final IColumn[] columns = new IColumn[3]; int col = 0; columns[col++] = new PropertyColumn(new Model("firstName"), "firstName", "firstName"); columns[col++] = new PropertyColumn(new Model("lastName"), "lastName", "lastName"); columns[col++] = new PropertyColumn(new Model("age"), "age", "age"); Now I want to filter of lastname so I replace the PropertyColumn by a : columns[col++] = new TextFilteredPropertyColumn(new ResourceModel("lastName"), "lastName" "lastName"); ?? but I got an error ... ...... Ok I think I have understood : the getFilterModel method of TextFilteredPropertyColumn return a PropertyModel bases on the form model. The form model is FilterStateModel based on the IFilterStateLocator. So the TextFilteredPropertyColumn set a property of the object used as the "getFilterState" of the IFilterStateLocator. So I just need to create a POJO and use it as the structure to store the filter state. I can use a People (I filter on the same column) but I prefer to use another class (I have some multicolumns filter..) So : 1/ create a POJO FilterState with a string property name "filterdFirstName" (I use voluntary another attr name id order to be clear) 2/ set the initial filter State on the provider : provider.setFilterState(new IncidentFilter()); 3/ transform column in instances of IFilteredColumn, like TextFilteredPropertyColumn but be careful, the property is target and instanca of the FilterState ! that is what I was missing! new TextFilteredPropertyColumn(new Model("object."filterdFirstName""), "author", "author"); "object" is the property name of the filtestate in the FilterStateModel (which is an instance of IncidentFilter ""filterdFirstName" is the property of I want to set in the IncidentFilter 4/ implements IFilterStateLocator in the DataProvider public Object getFilterState() { return filter; } public void setFilterState(final Object state) { filter = (IncidentFilter) state; } 5/and use the filter in the iterator of the DataProvider for (final Incident incident : list) { if ((filter.getAuthor() != null) && ! incident.getAuthor().toLowerCase().contains(filter.getAuthor().toLowerCase())) { continue; } filteredList.add(incident); } -(this is some bad code (prefer filter in the DAO, use internal var to limit .toLowerCase calls...) : just to learn wicket filter? after I delete all and restart) 6/ And voilà it works! Awesome!! Just have to get the trick. > > > > Serkan Camurcuoglu wrote: > > you can try FilterToolbar > > > > > > Julien Graglia wrote: > >> Hi, > >> > >> I try to filter rows of a datatable : I already have sort the rows very > >> easily (using a SortableDataProvider) but now I need to filter some > >> columns.. which seems to me a rather "classic" task. > >> > >> I have found classes in > >> org.apache.wicket.extensions.markup.html.repeater.data.table.filter like > >> ChoiceFilter and IFilterStateLocator but I did not find any examples. It > >> seems to me that is what I need but I dont figure out how to use it > >> > >> I only found a post with a very short code like : final > >> DefaultDataTable table = new DefaultDataTable("datatable", > >> columns, provider, 30); > >> final FilterForm form = new FilterForm("filter-form", provider); > >> table.addTopToolbar(new FilterToolbar(table, form, provider)); > >> form.add(table); > >> form.add(new GoAndClearFilter("filter-buttons", form)); > >> add(form); > >> > >> but I dont know what html comes with that and how to implements the > >> filter. > >> > >> I have google that the "phonebook" application is using filter but I > >> can't get it. > >> I have to say that I dont know how to start with only the javadoc (how > >> to write html? simple example?) > >> > >> I you have a piece of code of how to use filter and > >> IFilterStateLocator... > >> > >> thx, > >> > >> > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org -- Julien Graglia NetCeler --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org