开发者

How to set item renderer for ListView in ext-gwt?

开发者 https://www.devze.com 2023-01-21 18:20 出处:网络
I have a ListView in ext-gwt and I\'m adding some custom data to it.How can I set an item renderer on the ListView?As of right now, whenever an item is added, there\'s just a small line representing e

I have a ListView in ext-gwt and I'm adding some custom data to it. How can I set an item renderer on the ListView? As of right now, whenever an item is added, there's just a small line representing each entry in the view.

Here's my basic code:

import com.extjs.gxt.ui.client.store.ListStore;
import com.开发者_如何学运维extjs.gxt.ui.client.widget.ListView;
import com.foo.bar.FooModelData;


private final ListStore<FooModelData> listStore = 
    new ListStore<FooModelData>();
private final ListView<FooModelData> listView = 
    new ListView<FooModelData>();

public initializeView()
{
    listView.setStore(listStore);
    listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
}

public void addItem(FooModelData data) {
    listStore.add(data);
}


public class FooModelData extends BaseModel
{
    public ModelDataInstance(Foo foo, String style)
    {
        setFoo(foo);
        setStyle(style);
    }

    public String getStyle()
    {
        return get("style");
    }

    public Foo getFoo()
    {
        return (Foo) get("foo");
    }

    public void setStyle(String style)
    {
        set("style", style);
    }

    public void setFoo(Foo foo)
    {
        set("foo", foo);
    }

}

Thanks for all help!


GXT uses a templating implementation. Using a simplified version of the Sencha explorer example you could use your data as follows (foo.name assumes foo is also a model:

public initializeView()
{
listView.setStore(listStore);
listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
listView.setTemplate(getTemplate());
}

private native String getTemplate() /*-{ 
 return ['<tpl for=".">',
 '<div class="{style}">{foo.name}</div>', 
 '</tpl>', 
 '<div class="x-clear"></div>'].join(""); 
}-*/;
0

精彩评论

暂无评论...
验证码 换一张
取 消