PDA

View Full Version : Grid with paging funcionality



laitinen
1 Feb 2010, 11:27 AM
Hi everyone,

I was wondering if anyone could provide an example of a Grid with "paging" functionality?

I am looking for something similar to http://www.extjs.com/examples/explorer.html#pagingbeanmodelgrid, but I want to use a MemoryProxy instead of a RpcProxy.

The data I want to present in the grid is Java Beans.

Any code example would be greatly appreciated!

Thanks!

Laitinen

micgala
2 Feb 2010, 2:22 AM
This is what you are looking for:
http://www.extjs.com/examples/explorer.html#localpaging

Regards,
Michel.

laitinen
2 Feb 2010, 2:49 AM
not exactly. That example uses Data objects derived from BaseModel. I want to use BeanModel instead, and that does not work the same way. At least it seems like it doesnt.

Laitinen

micgala
2 Feb 2010, 2:55 AM
A BeanModel is a BaseModel.
It works the same way.

What exactly is your problem?

siberian
2 Feb 2010, 9:20 PM
I use BeanModels in my paging grids.

Just make sure they really are BeanModels by creating your BeanModelReader. This will take an javabean that implements Serializable and convert it to a BeanModel that a paging grid can read.

We'll need code examples to debug your app any further.



ContentPanel cp ;

final RemoteServiceAsync service = RemoteService.Util.getInstance();

RpcProxy pagingProxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getPolicies((PagingLoadConfig) loadConfig, ARG_FOR_MY_APP_IGNORE, callback);
}
};

BeanModelReader reader = new BeanModelReader();
reader.setFactoryForEachBean(true);

loader = new BasePagingLoader(pagingProxy, reader);
loader.setRemoteSort(true);
loader.load(0, perPage);
store = new ListStore<BeanModel>(loader);
final PagingToolBar toolBar = new PagingToolBar(perPage);
toolBar.bind(loader);

// column model
ColumnConfig column = new ColumnConfig();
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

TextField<String> text = new TextField<String>();
text.setAllowBlank(false);

column = new ColumnConfig("name", "User Name", 300);
columns.add(column);
column = new ColumnConfig("address", "Address", 50);
columns.add(column);

ColumnModel cm = new ColumnModel(columns);

cp = new ContentPanel();
cp.setHeaderVisible(false);
cp.setIconStyle("icon-table");
cp.setAnimCollapse(true);
cp.setCollapsible(false);
cp.setLayout(new FitLayout());
cp.setSize(800, 300);

grid = new Grid<BeanModel>(store, cm);

grid.addPlugin(expander);
grid.getView().setForceFit(true);

grid.addListener(Events.CellClick, new GridResizeListener(cp));
grid.addListener(Events.Attach, new Listener<ComponentEvent>() {

public void handleEvent(ComponentEvent be) {
DeferredCommand.addCommand(new Command() {
public void execute() {
loader.load(0, perPage);
}
} );
}

});
grid.setLoadMask(true);
cp.add(grid);
cp.setBottomComponent(toolBar);

add(cp);

siberian
3 Feb 2010, 9:07 PM
Oh and don't forget to make your beans implement 'BeanModelTag'. If you don't they'll never populate.