PDA

View Full Version : How to add row to the grid



lichnost
14 Jan 2009, 7:57 AM
When I'm adding new item to grids store, grid showing only n rows i have added first time. Exactly newly added item appears on the last place of grid, but first item disappears(however store still contain it).

Seems like bug.
Any suggestions

Example code below

public void onModuleLoad() {

List<TestBean> beanList = new ArrayList<TestBean>();

TestBean bean = new TestBean();
bean.setName("Charles");
TestBean nestedBean = new TestBean();
nestedBean.setName("Ray");
bean.setNested(nestedBean);
beanList.add(bean);

bean = new TestBean();
bean.setName("Paul");
nestedBean = new TestBean();
nestedBean.setName("McCartney");
bean.setNested(nestedBean);
beanList.add(bean);

List<ColumnConfig> lcc = new ArrayList<ColumnConfig>();
lcc.add(new ColumnConfig("name","name", 150));
lcc.add(new ColumnConfig("nested.name","nested.name", 150));

ListStore<BeanModel> store = new ListStore<BeanModel>();
store.add(BeanModelLookup.get().getFactory(TestBean.class).createModel(beanList));

final Grid<BeanModel> grid = new Grid<BeanModel>(store, new ColumnModel(lcc));
Button btn = new Button("Add", new SelectionListener<ButtonEvent>(){

@Override
public void componentSelected(ButtonEvent ce) {
TestBean newBean = new TestBean();
newBean.setName("New");
TestBean newNestedBean = new TestBean();
newNestedBean.setName("Row");
newBean.setNested(newNestedBean);
grid.getStore().add(BeanModelLookup.get().getFactory(TestBean.class).createModel(newBean));
}

});

RootPanel.get().add(grid);
RootPanel.get().add(btn);
}TestBean


public class TestBean implements BeanModelTag, Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;

private TestBean nested;

private String name;

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setNested(TestBean nested) {
this.nested = nested;
}

public TestBean getNested() {
return nested;
}
}

kolli
14 Jan 2009, 8:10 AM
The store gets updated automatically without calling the update method. Can you try removing

grid.getStore().update(null);


and check if it works?

lichnost
14 Jan 2009, 8:53 AM
The store gets updated automatically without calling the update method. Can you try removing

grid.getStore().update(null);
and check if it works?

well, I've try it already
I've tryed to find workaround with this, no result

kolli
14 Jan 2009, 9:07 AM
well it is working fine with me.. please add the size to the grid and rootpanel and you can see the scroll bars and the new entries added to the end of the previous entries..

I think the problem is with not setting the size

lichnost
14 Jan 2009, 10:13 AM
yeah, with setting size all works well
Thanks