简体   繁体   中英

How to create a checkbox (i dont want entire column) in a grid (GXT 3)

I am trying to add a checkbox(i dont want checkbox column) in grid (GXT 3.0), while getting values from model(VO/DTO) if i got null value then i want to add checkbox instead of null.

any idea?

Thanks in advance

You should oveeride the DataReader http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/data/shared/loader/class-use/DataReader.html

Assuming you have got a Grid with a CheckColumnConfig.

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

The associated Loader should look like :

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();

Now just implements some logic in you 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);
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM