0

我正在尝试在网格(GXT 3.0)中添加一个复选框(我不想要复选框列),同时从模型(VO/DTO)获取值,如果我得到空值,那么我想添加复选框而不是空值。

任何想法?

提前致谢

4

1 回答 1

0

您应该覆盖 DataReader http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/data/shared/loader/class-use/DataReader.html

假设您有一个带有 CheckColumnConfig 的网格。

CheckColumnConfig checkColumnConfig = new CheckColumnConfig ("myProperty" + prop.getId(), "myProperty"
                + prop.getId(), 40);

关联的 Loader 应如下所示:

RpcProxy<BeanModel> proxy = new RpcProxy<BeanModel>() {
        @Override
        protected void load(Object loadConfig, AsyncCallback<BeanModel> callback) {
            //call your rpc service
        }
    };
    final ListLoader<BaseListLoadResult<BeanModel>> loader = new BaseListLoader<BaseListLoadResult<BeanModel>>(
        proxy, new CustomGridBeanModelReader());
    loader.load();

现在只需在 DateReader 中实现一些逻辑:

public class CustomGridBeanModelReader implements DataReader<List<BeanModel>> {

/** The reader. */
private BeanModelReader reader = new BeanModelReader();

/**
 * Checks if is factory for each bean.
 * 
 * @return true, if is factory for each bean
 */
public boolean isFactoryForEachBean() {
    return reader.isFactoryForEachBean();
}

/* (non-Javadoc)
 * @see com.extjs.gxt.ui.client.data.DataReader#read(java.lang.Object, java.lang.Object)
 */
public List<BeanModel> read(Object loadConfig, Object data) {
    ListLoadResult<ModelData> models = reader.read(loadConfig, data);
    List<ModelData> modelsData = models.getData();
    Iterator<ModelData> itModels = modelsData.iterator();
    List<BeanModel> newModelsData = new ArrayList<BeanModel>();
    while (itModels.hasNext()) {
        BeanModel model = (BeanModel) itModels.next();
        Mybean myBean = model.getBean();
        //add some logic
        if ((myBean.getMyProperty() == null){
            model.set("myProperty" + myBean.getId(), true);
        }
        //add more logic
        //...
        newModelsData.add(model);
    }
    return newModelsData;
}

/**
 * Sets the factory for each bean.
 * 
 * @param factoryForEachBean the new factory for each bean
 */
public void setFactoryForEachBean(boolean factoryForEachBean) {
    reader.setFactoryForEachBean(factoryForEachBean);
}

}

于 2012-06-26T15:21:36.913 回答