0

I want to make a Grid Cell editable based on the data in that cell.

The cell accepts a String. so, i am adding a Text editor as follow:

 final GridInlineEditing<ModelData> editableGrid = new GridInlineEditing<ModelData>(grid);

    int columnCount = grid.getColumnModel().getColumnCount();
   final TextField text = new TextField();
    for(int i=1;i<columnCount-1;i++)
    {
        final ColumnConfig<ModelData,String> config = grid.getColumnModel().getColumn(i);        
          editableGrid.addEditor(config, text);
    }

and also.when i was creating the grid

config.setCell(new AbstractCell<String>() {


           @Override
           public void render(Context context, String value, SafeHtmlBuilder sb)
           {
               ModelData model  = getGrid().getStore().get(context.getIndex());
               if(null==value)
               {
                   value = "";
               }
               if(model.getName().equals("vivek") {
                   sb.appendHtmlConstant("<div style=\"background-color:#E9967A;\">");
                   sb.appendHtmlConstant((String)value);
                   sb.appendHtmlConstant("</div>");

                 }
                else{

                     sb.appendHtmlConstant("<span>" + value + "</span>");            
                }
           }


   });

But, i could not make the required field editable( I am able to make them colored). getGrid(), is a method that simply returns the grid

Then, i tried with setting editor to TextField with Custom TextInputCell, but this does not accepts HTML.

So, how can i achieve this. Making a Grid cell editable, based on the data.

Vivek Vardhan
  • 1,118
  • 3
  • 21
  • 44
  • http://stackoverflow.com/questions/16070953/gxt-3-x-editorgrid-choose-cell-editor-type-on-a-cell-by-cell-basis http://stackoverflow.com/questions/10632458/how-to-add-css-to-selected-row-in-treegrid-gxt-3 These 2 discussed the same problem, but i could not figure out making editable – Vivek Vardhan Dec 24 '13 at 12:07

1 Answers1

2

I found answer myself :)

editableGrid.addBeforeStartEditHandler(new BeforeStartEditHandler<ModelData>() {

@Override
public void onBeforeStartEdit(BeforeStartEditEvent<ModelData> event) {    
    ModelData data = grid.getStore().get(event.getEditCell().getRow());

    if(condition)
    event.getSource().getEditor(event.getSource().getEditableGrid().getColumnModel().getColumn(event.getEditCell().getCol())).enable();
            }
    else {
     event.getSource().getEditor(event.getSource().getEditableGrid().getColumnModel().getColumn(event.getEditCell().getCol())).disable();
        }
}
Vivek Vardhan
  • 1,118
  • 3
  • 21
  • 44