You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Julien Graglia <jg...@netceler.com> on 2009/04/15 18:48:48 UTC

filtering a datatable

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,

-- 
Julien Graglia
NetCeler


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by TahitianGabriel <gl...@piti.pf>.
Hi,

You'll find everything you need in the phonebook application :
https://wicket-stuff.svn.sf.net/svnroot/wicket-stuff/trunk/wicketstuff-core/phonebook/
https://wicket-stuff.svn.sf.net/svnroot/wicket-stuff/trunk/wicketstuff-core/phonebook/ 

Regards,

Gabriel.



julien Graglia wrote:
> 
> 
> I you have a piece of code of how to use filter and
> IFilterStateLocator...
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/filtering-a-datatable-tp23062814p27214593.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by Julien Graglia <jg...@netceler.com>.
I reply to myself... I just have found
http://www.nabble.com/Problems-with-clearing-of-filter-form-td16098239.html


I have to include the table in a form with some form specific components
(focus-restore and focus-tracker)

        <form wicket:id="filter-form">
        			<input type="hidden" name="tracker"
        wicket:id="focus-tracker"/> 
                	<table wicket:id="datatable"></table>
        			<span wicket:id="focus-restore">[call to focus restore
        script]</span> 
        </form>
        
and here is the java :
		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);
		add(form);

Next I have read in FilterToolbar that the filter are found by  using
columns with instances of IFilteredColumn like FilteredAbstractColumn...

So I just replace the column declaration : 

before : 
        new PropertyColumn(new Model("author"), "author", "author")

after (with filter)
        new TextFilteredPropertyColumn(new Model("author"), "author",
        "author");

and hop, the column header change in a texfield! great!


when I enter some text I got an error (Attempted to set property value
on a null object. Property expression: author Value: go) .. but it's
seems better...


Le mercredi 15 avril 2009 à 18:48 +0200, Julien Graglia a écrit :
> 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,

-- 
Julien Graglia
NetCeler


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by orkun ozen <sk...@gmail.com>.


julien Graglia wrote:
> 
> 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-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
> 
> -- 
> Julien Graglia
> NetCeler
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

Hello, 

I am currently working on the same thing, I am real wicket newbie and the
only helpful post I could find around was yours but unfortunately I havenT
been able to understand the classes you use. 

Could you maybe include some of your code? 
I am basicly stuck in the implementation of  IfilterState..

thanks 

-- 
View this message in context: http://old.nabble.com/filtering-a-datatable-tp23062814p27197797.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by Julien Graglia <jg...@netceler.com>.
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-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org

-- 
Julien Graglia
NetCeler


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by Serkan Camurcuoglu <Se...@telenity.com>.
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..



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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: filtering a datatable

Posted by Serkan Camurcuoglu <Se...@telenity.com>.
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org