PDA

View Full Version : paging - grid is not reloading correctly



kwasek
29 Jan 2010, 3:37 AM
Hi,
I have a problem with grid whem paging . I'll show my code :

Main class:

public class KontrahenciPanel extends ContentPanel{

public Grid<ModelData> grid;
public ColumnModel cm;
public ListStore store;
public PagingToolBar toolBar;

public KontrahenciPanel(){
cp=this;

ks = new KontrahenciStore();
listaRegionow=ks.getWszystkieRegiony();
listaTypowKontrahentow=ks.getTypyKontrahentow();
listaPracownikow=ks.getPracownicy();
setLayout(new RowLayout(Orientation.HORIZONTAL));
setBodyBorder(true);
setHeaderVisible(false);

setHeight((int)(Window.getClientHeight()-80));
createMenu(this);

this.add(makeGrid2() );


setButtonAlign(HorizontalAlignment.LEFT);

}


public void setFilterOnGrid(String filtr){
store = new ListStore(ks.getALLKonts(filtr));

grid.reconfigure(store, cm);

toolBar.bind((PagingLoader<PagingLoadResult<ModelData>>) grid.getStore().getLoader());

PagingLoadConfig conf = new BasePagingLoadConfig();
conf.setOffset(0);
conf.setLimit(100);
grid.getStore().getLoader().load(conf);



}

private void refreshEdit(Kontrahenci kont){
idkT.setValue(""+kont.getIdkontrahenci());
skrotT.setValue(kont.getSkrot());
nazwaT.setValue(kont.getNazwa());
ulicaT.setValue(kont.getUlica());
miastoT.setValue(kont.getMiasto());
kodpoczT.setValue(kont.getKodPocztowy());
nipT.setValue(kont.getNip());
matkaT.setValue(""+kont.getIdkontrMatki());
kieroT.setValue(kont.getKierownik());
tel1T.setValue(kont.getTel1());
tel2T.setValue(kont.getTel2());
faxT.setValue(kont.getFax());
emailT.setValue(kont.getEmail());


regCMB.setValue(regCMB.getStore().findModel("idregiony", kont.getIdregionyFk()));

}

private void createMenu(ContentPanel panel) {
.
.
.
kartKontrMI = new MenuItem("Regionalna");
kartKontrMI.addSelectionListener(new SelectionListener<MenuEvent>() {

@Override
public void componentSelected(MenuEvent ce) {

setFilterOnGrid(" WHERE Visible=1 AND IDRegiony_FK="+GlobalVAR.pracownik.getIdregionyFk());
}
});
menu.add(kartKontrMI);
btn.setMenu(menu);
.
.
.
.
.
kartKontrMI = new MenuItem("nowy");

kartKontrMI.addSelectionListener(new SelectionListener<MenuEvent>() {

@Override
public void componentSelected(MenuEvent ce) {

KontrahentEditWND kwnd = new KontrahentEditWND(cp);
kwnd.show();
}
});
.
.
.
.


}

private Grid<ModelData> makeGrid2(){
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("idkontrahenci");
column.setHeader("idkontrahenci");
column.setWidth(50);
configs.add(column);

column = new ColumnConfig();
column.setId("skrot");
column.setHeader("skrot");

column.setWidth(150);
configs.add(column);

column = new ColumnConfig();
column = new ColumnConfig();
column.setId("nazwa");
column.setHeader("nazwa");

column.setWidth(150);
configs.add(column);

column = new ColumnConfig();
column.setId("ulica");
column.setHeader("ulica");

column.setWidth(150);
configs.add(column);

column = new ColumnConfig();
column.setId("miasto");
column.setHeader("miasto");

column.setWidth(150);
configs.add(column);

column = new ColumnConfig();
column.setId("kodPocztowy");
column.setHeader("k. pocztowy");

column.setWidth(150);

configs.add(column);

column = new ColumnConfig();
column.setId("nip");
column.setHeader("nip");

column.setWidth(150);

configs.add(column);

column = new ColumnConfig();
column.setId("kierownik");
column.setHeader("kierownik");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("tel1");
column.setHeader("tel1");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("tel2");
column.setHeader("tel2");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("fax");
column.setHeader("fax");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("email");
column.setHeader("email");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("idregionyFk");
column.setHeader("idregionyFk");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("idpracownicyFk");
column.setHeader("idpracownicyFk");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("visible");
column.setHeader("visible");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("idkontrTypFk");
column.setHeader("idkontrTypFk");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("preferowany");
column.setHeader("preferowany");

column.setWidth(150);
column.setHidden(true);
configs.add(column);

column = new ColumnConfig();
column.setId("idopiekun2");
column.setHeader("idopiekun2");

column.setWidth(150);
column.setHidden(true);
configs.add(column);



cm = new ColumnModel(configs);

store = new ListStore(ks.getALLKonts(" WHERE Visible=1 AND IDKontrahenci IN ( SELECT IDKontrahenci_FK FROM sync_kontrahenci WHERE IDTelefony_FK="+GlobalVAR.pracownik.getIdtelefonyFk()+")"));

toolBar = new PagingToolBar(100);

toolBar.bind((PagingLoader<PagingLoadResult<ModelData>>) store.getLoader());

grid = new Grid<ModelData>(store, cm){

protected void onAttach(){
super.onAttach();

PagingLoadConfig conf = new BasePagingLoadConfig();
conf.setOffset(0);
conf.setLimit(100);
grid.getStore().getLoader().load(conf);

}
};

setBottomComponent(toolBar);
//toolBar.refresh();
grid.setLoadMask(true);
toolBar.setEnabled(true);

grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<ModelData>>() {
public void handleEvent(SelectionChangedEvent<ModelData> be) {

wybranyKontrahent=new Kontrahenci();
wybranyKontrahent.setIdkontrahenci(Integer.parseInt(be.getSelectedItem().get("idkontrahenci").toString()));
wybranyKontrahent.setSkrot(be.getSelectedItem().get("skrot").toString());
wybranyKontrahent.setNazwa(be.getSelectedItem().get("nazwa").toString());
wybranyKontrahent.setUlica(be.getSelectedItem().get("ulica").toString());
wybranyKontrahent.setMiasto(be.getSelectedItem().get("miasto").toString());
wybranyKontrahent.setKodPocztowy(be.getSelectedItem().get("kodPocztowy").toString());
wybranyKontrahent.setNip(be.getSelectedItem().get("nip").toString());
wybranyKontrahent.setIdkontrMatki(Integer.parseInt(be.getSelectedItem().get("idkontrMatki").toString()));
wybranyKontrahent.setKierownik(be.getSelectedItem().get("kierownik").toString());
wybranyKontrahent.setTel1(be.getSelectedItem().get("tel1").toString());
wybranyKontrahent.setTel2(be.getSelectedItem().get("tel2").toString());
wybranyKontrahent.setFax(be.getSelectedItem().get("fax").toString());
wybranyKontrahent.setEmail(be.getSelectedItem().get("email").toString());
wybranyKontrahent.setIdregionyFk(Integer.parseInt(be.getSelectedItem().get("idregionyFk").toString()));
wybranyKontrahent.setIdpracownicyFk(Integer.parseInt(be.getSelectedItem().get("idpracownicyFk").toString()));
//wybranyKontrahent.setMiasto(be.getSelectedItem().get("miasto").toString());
wybranyKontrahent.setVisible(Short.parseShort(be.getSelectedItem().get("visible").toString()));
wybranyKontrahent.setIdkontrTypFk(Integer.parseInt(be.getSelectedItem().get("idkontrTypFk").toString()));
wybranyKontrahent.setPreferowany(Short.parseShort(be.getSelectedItem().get("preferowany").toString()));
wybranyKontrahent.setIdopiekun2(Integer.parseInt(be.getSelectedItem().get("idopiekun2").toString()));
//Info.display("", wybranyKontrahent.getNazwa());
}

});

grid.setBorders(true);
grid.setStripeRows(true);
grid.setWidth(830+150);
grid.setHeight((int)(Window.getClientHeight()*.8));


return grid;
}
}



-------------------------------------------------------------

So.
Whem I launch app, grid is loading perfectly. When I click on 'nowy' and

KontrahentEditWND kwnd = new KontrahentEditWND(cp);
kwnd.show();

is fired ( KontrahentEditWND is a class extended with Window ) and then I close it and refresh the grid using refresh button on paging toolbar, or click next or prvious page, the grid is not reloading properly. I mean for example I click next page. Toolbar and grid are grey and after a while toolbar is properly refreshed but the grid is still greyed. When I click again on next page , both of them are refreshing correctly.

Any ideas?

terciofilho
29 Jan 2010, 12:35 PM
Dude, don't understand me wrong, but your code is a totally mess!

Why do you create a new ListStore every time you filter a data??
You could extend the ListStore and add a custom filter method to it.

Every time you create a new store to your grid, you must reconfigure it. Take a look at grid.reconfigure function.

Take a look at some design patterns, it may help you with code organization.

I hope it can help.