Filtering a ListGrid at module startup

Hello,

For a project we choose to use smartgwt 2.5.

The business case:

  • we use a ListGrid that is populated by mean of a smartgwt Datasource (listGrid.setDataSource({our datasource object}).
  • On our page, we have a “filter selector” to filter the list.
  • For example, if we want to filter on “status”, we do:
    Criterion newCriterion = new Criterion(“status”, OperatorId.IEQUALS, “Nieuw”);
    listGrid.fetchData(newCriterion);

When we open the page (where we put the ListGrid), 2 solutions (depending on our business cases):

  • We want to display all the items WITHOUT automatically selecting a filter (so, all records are displayed when page starts).
    ==> NO PROBLEM

  • We want to automatically apply a filter when the page is launched.
    ==> PROBLEM !!

The filter is not applied, or more exactly: all the rows are always displayed and if we try to select an other filter, the list seems to be frozen). It’s like if the rendering of the list became crazy !

So, what I did:

  1. At the end of the “onModuleLoad” method, I displayed an Alert (for test purpose, just after the “setFilter” call)

==> Alert is displayed and after closing the alert, the filter is WELL applied, and all’s working well.

  1. OK, so, this is asynchronous, I want to apply the filter when I’m sure that the onModuleLoad is finished, I used a Scheduler, like that:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
                         setFilter();
		}
	});

==> Same behavior, doesn’t work

  1. As I workaround, cause we had to quickly deliver a solution, I did the following:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {

			Timer t = new Timer() {

				@Override
				public void run() {
					setFilter();
				}
			};

			t.schedule(150);
		}
	});

==> I used a timer to wait a little bit before setting filter ==> it’s working.

But we don’t like this “timer” solution.

So,

  • Has anyone already seen this behavior before ?
  • Do you have a solution to be able to filter a ListGrid when module starts ?

Remark: an other solution would to reset the datasource every time we want to set a filter. But this is not a performant solution (back to server) and we would like to use the smartgwt ListGrid features.

Any information is welcome !!

Thanks a lot

Cristophe

No need for any of this.. what you probably did is both setAutoFetchData(true) and had a manual call to fetchData(criteria). Use one or the other approach, using both will result in two attempts to fetch and the criteria from the second fetch will win.

Actually I wrote earlier that it was working… but after having some more tests… it actually doesn’t work.

So, I set the AutoFetchData to false and set the filter manually at the end of the onModuleLoad method.

Same problem occurs.

Some more help is welcome !

Thanks a lot

I didn’t know if just editing my previous message will raise a notification… So, my problem still occurs…

Thanks a lot

This is a very basic use case, most likely you have a simple coding error. Try to put together a standalone test case as though you were trying to demonstrate a framework issue and you will likely find the problem in your code.

Even if your remarks about the auto fetch mad me clean a little bit my code (thanks), the problem was not there.

I had to make my datasource working as “client only”.

Problem is solved.

Thanks