如何在GXT 2.2.3中的EditorGrid中禁用和启用单元格

时间:2014-04-15 04:26:53

标签: java gwt grid gxt

我使用GXT 2.2.3创建了EditorGrid。现在我尝试根据另一个单元格中的值禁用和启用单元格,即SimpleComboBox。我尝试了下面的代码

Listener<GridEvent<AttendanceCaseCreationModel>> gridAfterEditListener = new Listener<GridEvent<AttendanceCaseCreationModel>>() {

        @Override
        public void handleEvent(GridEvent<AttendanceCaseCreationModel> be) {
            AttendanceCaseCreationModel data = be.getModel();
             String val = data.get("event");

             if(val.equalsIgnoreCase("Remove Attendance")){

                data.set("checkinDate","");


                  grid.getColumnModel().getColumnById("checkinDate").getEditor().disable();
                  grid.getStore().update(data); 
                  grid.getView().refresh(true);


             }
             else {
                 data.set("checkinDate",""); 
                 grid.getColumnModel().getColumnById("checkinDate").getEditor().enable();
             grid.getStore().update(data); 
                 grid.getView().refresh(true);

             }

        }
    };
    grid.addListener(Events.AfterEdit, gridAfterEditListener); 

但它不能满足我的期望。它会禁用整个列,一旦它被禁用就不启用。

我的要求是根据GXT 2.2.3的EditorGrid中的另一个单元格值禁用和启用单元格。

  

没人能回答这个问题?

1 个答案:

答案 0 :(得分:1)

考虑禁用和启用单元格,我只是隐藏并使用CSS显示单元格。以下是我的代码,可以帮助我满足这一要求。

GridCellRenderer<AttendanceCaseCreationModel> checkinRenderer=new GridCellRenderer<AttendanceCaseCreationModel>() {

        @Override
        public Object render(AttendanceCaseCreationModel model, String property,
                ColumnData config, int rowIndex, int colIndex,
                ListStore<AttendanceCaseCreationModel> store,
                Grid<AttendanceCaseCreationModel> grid) {

            String color="pink";
            if(eventcombo.getValue()!=null){


                if(eventcombo.getRawValue().equalsIgnoreCase("Forgot To Checkin") || 
                        eventcombo.getRawValue().equalsIgnoreCase("Mark/Modify Attendance")){
                    color="pink";
                }
                else{

                    config.style=config.style+ ";visibility: hidden;";
                }

            }

            config.style=config.style+ ";background-color:" + color  + ";";
            config.style=config.style+ ";display: block;";
            Object value = model.get(property);
            return value;

        }
    };