How to keep row selected after pagination grid refresh?

282 views
Skip to first unread message

Tomeo

unread,
Nov 19, 2010, 3:35:17 AM11/19/10
to Google Web Toolkit
Hi folks,

I have a below a simple scenario:

1. I have a grid populated with data
2. I select any 1 row from grid - data with a specific "Object
Id" [internal id]
3. I press a refresh button from a paginationToolbar
4. data are refreshed
5. no row from grid is being selected.

Question 1:
How can I change a step 5, so after refresh a row with specific Object
Id (from step 2) would be automaticaly selected?


I tried to implement a LoadListener to loader, but it seems like I'm
incorrectly selecting a row from my grid.
Here is a bit of my code:

1. A global variable of type "Zakazka" to store a Zakazka before
refresh occures (the one which should be selected after refresh):
Code:

private Zakazka selectedZakazka;



2. Here is my grid definition with loader's load listener
Code:


RpcProxy<PagingLoadResult<Zakazka>> proxy = new
RpcProxy<PagingLoadResult<Zakazka>>() {
@Override
public void load(Object loadConfig,
AsyncCallback<PagingLoadResult<Zakazka>> callback) {
Tracing.Log("ZakazkyAktivne.RpcProxy.load.before");
service.getZakazky((PagingLoadConfig) loadConfig,
callback);
Tracing.Log("ZakazkyAktivne.RpcProxy.load.after");
}
};

// loader
final PagingLoader<PagingLoadResult<ModelData>> loader = new
BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
loader.setRemoteSort(true);

ListStore<Zakazka> store = new ListStore<Zakazka>(loader);
pagingToolBar = new PagingToolBar(50);
pagingToolBar.bind(loader);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("object_id", "Object Id", 80));
columns.add(new ColumnConfig("cislo_dokladu", "Číslo dokladu",
100));
ColumnConfig created = new ColumnConfig("created", "Dátum
vytvorenia", 105);
created.setDateTimeFormat(DateTimeFormat.getFormat("dd.MM.yyyy
HH:mm:ss"));
columns.add(created);
columns.add(new ColumnConfig("objednavatel", "Objednavatel",
120));
columns.add(new ColumnConfig("stredisko", "Stredisko", 150));
columns.add(new ColumnConfig("stav_zakazky_id", "Id stavu
zakazky", 60));
columns.add(new ColumnConfig("stav_zakazky_kod", "Kód stavu
zakazky", 100));
columns.add(new ColumnConfig("stav_zakazky", "Stav zakazky",
100));
columns.add(new ColumnConfig("stav_zakazky_zmenil_uziv_meno",
"Zakazku změnil", 100));
ColumnConfig updated = new ColumnConfig("stav_zakazky_zmena",
"Dátum změny", 105);
updated.setDateTimeFormat(DateTimeFormat.getFormat("dd.MM.yyyy
HH:mm:ss"));
columns.add(updated);


ColumnModel cm = new ColumnModel(columns);

gridZakazka = new Grid<Zakazka>(store, cm);
gridZakazka.setStateId("pagingGridExample");
gridZakazka.setStateful(true);
gridZakazka.addListener(Events.Attach, new
Listener<GridEvent<Zakazka>>() {
public void handleEvent(GridEvent<Zakazka> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(50);

Map<String, Object> state = gridZakazka.getState();
if (state.containsKey("offset")) {
int offset = (Integer)state.get("offset");
int limit = (Integer)state.get("limit");
config.setOffset(offset);
config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config.setSortField((String)state.get("sortField"));

config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
}
loader.load(config);
}
});


gridZakazka.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<Zakazka>>() {
public void handleEvent(SelectionChangedEvent<Zakazka>
be) {
if (be.getSelection().size() > 0) {
Tracing.Log("Grid selection changed");
formBindings.bind((ModelData)
be.getSelection().get(0));

setZakazkaDetailToolBar(be.getSelectedItem().getZakazkaObjectId(),

be.getSelectedItem().getZakazkaStavZakazkyId());

//
getLogZakazkaGrid(be.getSelectedItem().getZakazkaObjectId());
//pagingToolBarLog.refresh();
} else {
Tracing.Log("Nothing selected");
formBindings.unbind();
zakazkaDetailToolBar.removeAll();
}
}
});

loader.addLoadListener(new LoadListener() {
@Override
public void loaderLoad(LoadEvent le)
{
// Run your selection logic here
Tracing.Log("loaderLoad invoked!");


gridZakazka.getSelectionModel().select(selectedZakazka, false);
Tracing.Log("selectedZakazka selected");
}
});



gridZakazka.setLoadMask(true);
gridZakazka.setBorders(true);

3. Selected zakazka is remembered before refresh using a below code:
Code:

public void changeZakazkaStatus(Integer zakazkaId,
Integer novyStatusId) {
final DatabaseServiceAsync service = (DatabaseServiceAsync)
Registry.get(Agdoprava.SERVICE);
AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {

public void onFailure(Throwable caught) {
System.out.println(caught.getMessage());
}

public void onSuccess(Boolean result) {
if (result) {
Tracing.Log("Zakazka STATUS updated successfully!");

selectedZakazka =
gridZakazka.getSelectionModel().getSelectedItem();
Tracing.Log("Selected zakazka Object ID:" +
selectedZakazka.getZakazkaObjectId());


// refresh main grid
pagingToolBar.refresh();
Tracing.Log("Refresh OK");
}
else {
Tracing.Log("Zakazka STATUS update failed!");
}

}
};

// execute RPC
service.updateZakazkaStatus(zakazkaId, novyStatusId,
StaticDataController.LoggedUzivatelId, callback);

}

4. Tracing log
Code:

2010-11-19 09:06:13.739| Zakazka STATUS updated successfully!
2010-11-19 09:06:13.739| Selected zakazka Object ID:123
2010-11-19 09:06:14.066| ZakazkyAktivne.RpcProxy.load.before
2010-11-19 09:06:14.082| ZakazkyAktivne.RpcProxy.load.after
2010-11-19 09:06:14.082| Refresh OK
ZakazkaManager.getZakazky()
2010-11-19 09:06:14.436| Nothing selected
2010-11-19 09:06:14.877| loaderLoad invoked!
2010-11-19 09:06:14.877| selectedZakazka selected

From my tracing log I can see, that selectedZakazka is set correctly
and prior refresh and also that loader.LoadListener is invoked after
refresh. Just a row in grid stays unselected. So, I assume a piece of
code in loader's LoadListener [in step 2 above] is incorrect, or
uncomplete.

Could you please suggest how to correct it, so selectedZakazka will be
also selected after refresh?


Many thanks,
Tomas

Ahmed Shoeib

unread,
Nov 20, 2010, 11:48:12 AM11/20/10
to Google Web Toolkit
i also need to know how to refresh a row with specific Object
>       columns.add(new ColumnConfig("cislo_dokladu", "Èíslo dokladu",
> 100));
>       ColumnConfig created = new ColumnConfig("created", "Dátum
> vytvorenia", 105);
>       created.setDateTimeFormat(DateTimeFormat.getFormat("dd.MM.yyyy
> HH:mm:ss"));
>       columns.add(created);
>       columns.add(new ColumnConfig("objednavatel", "Objednavatel",
> 120));
>       columns.add(new ColumnConfig("stredisko", "Stredisko", 150));
>       columns.add(new ColumnConfig("stav_zakazky_id", "Id stavu
> zakazky", 60));
>       columns.add(new ColumnConfig("stav_zakazky_kod", "Kód stavu
> zakazky", 100));
>       columns.add(new ColumnConfig("stav_zakazky", "Stav zakazky",
> 100));
>       columns.add(new ColumnConfig("stav_zakazky_zmenil_uziv_meno",
> "Zakazku zmìnil", 100));
>       ColumnConfig updated = new ColumnConfig("stav_zakazky_zmena",
> "Dátum zmìny", 105);

John LaBanca

unread,
Nov 20, 2010, 6:07:40 PM11/20/10
to google-we...@googlegroups.com
It sounds like you are using gwt-ext.  Have you tried posting your question on their forum?

Thanks,
John LaBanca
jlab...@google.com


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Blagoja Chavkoski

unread,
Nov 20, 2010, 6:35:05 PM11/20/10
to google-we...@googlegroups.com
This question is for ext gwt forum, but i had implemented some code close to this one, and I had the same problem!!
Its interesting that I notised the problem is on adding the html css style for the selected row..its just not showing,
the related model row is correct and all related listeners are fired...but the view row style is never set or set and cleared...
I investigated in the GridView class but till that point all was ok and fired prop ..it looks like something is going on after that..
the relation between gwt(resp for the css styles adding in widget, and the component class extension from ext) but no
time to spent more and just continue without it..:)

regards and hope u gonna solve it,
if u do..u can notify here also...

B

Ahmed Shoeib

unread,
Nov 21, 2010, 3:19:04 PM11/21/10
to Google Web Toolkit
i don't use gwt-ext
i use gwt
how can refresh selected Row ??

On Nov 21, 1:35 am, Blagoja Chavkoski <baze...@gmail.com> wrote:
> This question is for ext gwt forum, but i had implemented some code close to
> this one, and I had the same problem!!
> Its interesting that I notised the problem is on adding the html css style
> for the selected row..its just not showing,
> the related model row is correct and all related listeners are fired...but
> the view row style is never set or set and cleared...
> I investigated in the GridView class but till that point all was ok and
> fired prop ..it looks like something is going on after that..
> the relation between gwt(resp for the css styles adding in widget, and the
> component class extension from ext) but no
> time to spent more and just continue without it..:)
>
> regards and hope u gonna solve it,
> if u do..u can notify here also...
>
> B
>
> On Sun, Nov 21, 2010 at 12:07 AM, John LaBanca <jlaba...@google.com> wrote:
> > It sounds like you are using gwt-ext.  Have you tried posting your question
> > on their forum?
>
> > Thanks,
> > John LaBanca
> > jlaba...@google.com
> >> google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/google-web-toolkit?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
>
> ...
>
> read more »

John LaBanca

unread,
Nov 21, 2010, 8:50:23 PM11/21/10
to google-we...@googlegroups.com
@ahmedelsayed.shoeib -

Are you using a CellTable?  If so, you can push new data into a row to refresh it:
myCellTable.setRowData(rowIndexToRefresh, Collections.singletonList(valueToRefresh));

Thanks,
John LaBanca
jlab...@google.com


To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

Ahmed Shoeib

unread,
Nov 23, 2010, 10:15:34 AM11/23/10
to Google Web Toolkit
Thanks for your help

On Nov 22, 3:50 am, John LaBanca <jlaba...@google.com> wrote:
> @ahmedelsayed.shoeib -
>
> Are you using a CellTable?  If so, you can push new data into a row to
> refresh it:
> myCellTable.setRowData(rowIndexToRefresh,
> Collections.singletonList(valueToRefresh));
>
> Thanks,
> John LaBanca
> jlaba...@google.com
>
> On Sun, Nov 21, 2010 at 3:19 PM, Ahmed Shoeib <ahmedelsayed.sho...@gmail.com
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages