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