Problem with setTestData function

Hello,

I use the DataSource.setTestData(datas) method and attach the datasource to a listGrid
When I change dynamically the Test Datas, with a button for example, My ListGrid (and maybe my DataSource) is not updated.

What is the problem and how to solve it ?

Thank you by advance.

do a listGrid.fetchData() to get the new data when you “…change dynamically the Test Datas…”

I did :

dataSource.setTestData(donnees);
grid.getchData();

but it doesn’t work…

maybe this post will help: http://forums.smartclient.com/showpost.php?p=15373&postcount=12

Tried :

dataSource.setTestData(new DataClass[0]);
dataSource.setTestData(donnees);
grid.fetchData();

and

dataSource.setTestData(new DataClass[0]);
grid.fetchData();
dataSource.setTestData(donnees);
grid.fetchData();

None works.

Please re-read the post you were linked to. It says to call setData() on the grid with an empty array, not setTestData on the DataSource.

Listgrids don’t have any setTestData method which is a DataSource method.

you need to call setData on the grid and not setTestData on the datasource

My mistake… thank you.

It works fine ! Fantastic !

But there is only one little little little problem… My ListGrid which had a groupBy method is not grouped by my field anymore (after the second call of setData)

well this is a quite ugly hack just to sync the listgrid to the datasource it has (of course it has rpc, setTestData..), Isomorphic do you think we could get a preview of the RPC data source by the end of the month? Many of us need to do all those hacks just to do basic things using pojos and smartGWT…

Ontopic:
Well now that you have the new data I think you could call to group it again.
I think that you should get the used grouping on the grid before calling setData and then put it again after the fetch…

Offtopic:
P.S: Isomorphic it’s not just the people that come from GWT-EXT that needs pojos and RPC, by creating SmartGWT and exposing the SmartClient framework to java, all java programmers are used to the Pojos and RPC’s and will want the feature available, I mean SmartGWT applications are made in java so why should not the pojo support be there anyway…

Already tried grid.groupBy or grid.groupByField after the fetchData…
Thank you for trying :wink:

Grouping will work, but make sure you do it only once the data is loaded (use the callback from fetchData()).

fetchData needs a criteria to use the DSCallback but I don’t need one.

How can I do?

public void setTestData(DataClass[] donnees) {
		if (dataSource != null) {
			grid.setData(new ListGridRecord[0]);
			dataSource.setTestData(donnees);
			grid.fetchData(null, new DSCallback(){

				public void execute(DSResponse response, Object rawData,
						DSRequest request) {
					grid.groupBy("type");					
				}
				
			});
		}
	}

It doesn’t work…

What exactly happens?

Can you post a standalone testcase?

Mihai this approach worked for you, right?

I have a ListGrid and a button.
My ListGrid is grouped by type.
The button calls the setData function above.

I click on the button the first time. My ListGrid is filled with test datas and grouped by type.
I click the second time. Same thing but I don’t have the group anymore.

I just tested and no, it’s not working!
But I found the solution:
You have to ungroup before calling the setData with the empty rows list, so sourivore for your code to work, you should do:

public void setTestData(DataClass[] donnees) {
		if (dataSource != null) {
			grid.ungroup(); // <----- ADDED THIS LINE HERE ------
			grid.setData(new ListGridRecord[0]);
			dataSource.setTestData(donnees);
			grid.fetchData(null, new DSCallback(){

				public void execute(DSResponse response, Object rawData,
						DSRequest request) {
					grid.groupBy("type");					
				}
				
			});
		}
	}

So sourivore can you confirm that in this way it is working?

Yep! It works.
Thanks a lot.

That is a strange behaviour though :slight_smile: