PDA

View Full Version : Grid reconfigure method not working



qbert65536
31 Aug 2009, 3:44 PM
I have the following class which I ripped from the grid example in the demo.

However when I try to call reloadSongList() , all I get is a blank grid and no rpc calls get sent back to the service ?

Am I missing something?

Thanks! Love GXT!




/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
package com.charlie.client.panels;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.charlie.client.modeldata.SongModelData;
import com.charlie.client.services.SiteServiceImpl;
import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PlaylistPanel extends LayoutContainer {

private static final int PAGING_SIZE = 50;
private Grid<SongModelData> localGrid;
private static ColumnModel columnModel;

static
{
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("songName", "Song Name", 200);
columns.add(column);
columns.add(new ColumnConfig("artist", "Artist", 150));
columns.add(new ColumnConfig("album", "Album", 100));
column = new ColumnConfig("sizeInBytes", "Size", 100);
column.setHidden(true);
columns.add(column);
columns.add(new ColumnConfig("genre", "Genre", 100));
column = new ColumnConfig("lengthInSeconds", "Length", 100);
column.setHidden(true);
columns.add(column);
columnModel = new ColumnModel(columns);

}

public void reloadSongList(Integer userId) {

ListStore<SongModelData> store = getListStore(getPagingLoader(userId));
ColumnModel cm = getColulmnModel();
localGrid.reconfigure(store, cm);
localGrid.unmask();
}


private static ColumnModel getColulmnModel() {
return columnModel;
}

private ListStore<SongModelData> getListStore(final PagingLoader<PagingLoadResult<ModelData>> loader) {
ListStore<SongModelData> store = new ListStore<SongModelData>(loader);
return store;
}

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

final PagingLoader<PagingLoadResult<ModelData>> loader = getPagingLoader(1);
ListStore<SongModelData> store = getListStore(loader);

final PagingToolBar toolBar = new PagingToolBar(PAGING_SIZE);
toolBar.bind(loader);

ColumnModel cm = getColulmnModel();
final Grid<SongModelData> grid = new Grid<SongModelData>(store, cm);
localGrid = grid;

grid.setStateId("pagingGridExample");
grid.setStateful(true);
grid.setAutoExpandColumn("songName");
grid.setLoadMask(true);
grid.setBorders(true);

grid.addListener(Events.RowDoubleClick, new Listener<GridEvent<SongModelData>>() {

public void handleEvent(GridEvent<SongModelData> be) {
SongModelData data = be.getModel();
Window.alert(data.getUrl());

}

});

grid.addListener(Events.Attach, new Listener<GridEvent<SongModelData>>() {
public void handleEvent(GridEvent<SongModelData> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(PAGING_SIZE);

Map<String, Object> state = grid.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);
}
});

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(false);
panel.setAnimCollapse(false);

panel.setHeading("Playlist");
panel.setLayout(new FitLayout());
panel.add(grid);

panel.setBottomComponent(toolBar);

setLayout(new FitLayout());
add(panel);

}


private PagingLoader<PagingLoadResult<ModelData>> getPagingLoader(final Integer userId) {
RpcProxy<PagingLoadResult<SongModelData>> proxy = new RpcProxy<PagingLoadResult<SongModelData>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<SongModelData>> callback) {
SiteServiceImpl.getInstance().getPagedSongModelDataByUserId((PagingLoadConfig) loadConfig, userId, callback);
}
};

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

}

Feltros
1 Sep 2009, 3:27 AM
Isn't it loader.load(config); which actually makes the loader make the call to load information? You attach a new loader to the store but don't appear to ask it to load anything.

Arno.Nyhm
1 Sep 2009, 4:01 AM
shorter is to attach the proxy and the store only one time.

then change this


public void load(Object loadConfig, AsyncCallback<PagingLoadResult<SongModelData>> callback) {
SiteServiceImpl.getInstance().getPagedSongModelDataByUserId((PagingLoadConfig) loadConfig, userId, callback);
}


to read the userid from a global variable. then you just need only to do a reload on the loader and not create many new objects

qbert65536
1 Sep 2009, 1:23 PM
Both of those methods worked , calling load() will reload the grid.

Also using a global userId works better for me. Thanks!