Hi Isomorphic,
please see this BuiltInDS based testcase (v10.1p_2016-03-02).
BuiltInDS.java:
Please then change the lifespan of all shown animals to a value from the SelectItem.
If you do so like this
you'll see that if you start to edit rows, the desired effect (both, only status, only diet or none editable) is only there on the 2nd start of the row editor. The first start is always like the row edited before the current row.
So if you e.g. keep moving from "only status" to "only diet" rows back and forth (without doing any changes), always the wrong column is editable.
Additionally the ChangedHandler on the SelectItem does fire, but the effect of the change is not visible.
From the visual effect this is what I was seeing here, although I don't know if it is related.
Best regards
Blama
please see this BuiltInDS based testcase (v10.1p_2016-03-02).
BuiltInDS.java:
Code:
package com.smartgwt.sample.client; import java.util.LinkedHashMap; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.Criterion; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.SortSpecifier; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.events.ChangedEvent; import com.smartgwt.client.widgets.grid.events.ChangedHandler; import com.smartgwt.client.widgets.grid.events.RowEditorEnterEvent; import com.smartgwt.client.widgets.grid.events.RowEditorEnterHandler; import com.smartgwt.client.widgets.layout.VLayout; public class BuiltInDS implements EntryPoint { private VLayout mainLayout; private IButton recreateBtn; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); mainLayout = new VLayout(20); mainLayout.setWidth100(); mainLayout.setHeight100(); recreateBtn = new IButton("Recreate"); recreateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recreate(); } }); mainLayout.addMember(recreateBtn); recreate(); mainLayout.draw(); } private void recreate() { Window w = new Window(); w.setWidth("95%"); w.setHeight("95%"); w.setMembersMargin(0); w.setModalMaskOpacity(70); w.setTitle("ListGrid-editRow FormItems with canEdit(true/false) depending on another FormItem-Change not updated on change."); w.setShowMinimizeButton(false); w.setIsModal(true); w.setShowModalMask(true); w.centerInPage(); final ListGrid animalsGrid = new ListGrid(); animalsGrid.setHeight100(); animalsGrid.setAutoFetchData(false); animalsGrid.setCanEdit(true); animalsGrid.setDataSource(DataSource.get("animals")); ListGridField commonName = new ListGridField("commonName"); ListGridField scientificName = new ListGridField("scientificName"); LifeSpanLGF lifeSpan = new LifeSpanLGF("lifeSpan", animalsGrid); ListGridField status = new ListGridField("status"); ListGridField diet = new ListGridField("diet"); status.addChangedHandler(new ChangedHandler() { @Override public void onChanged(ChangedEvent event) { } }); animalsGrid.addRowEditorEnterHandler(new RowEditorEnterHandler() { @Override public void onRowEditorEnter(RowEditorEnterEvent event) { SC.logWarn("RowEditorEnterEvent"); Integer lifeSpan = event.getRecord().getAttributeAsInt("lifeSpan"); if (lifeSpan > 0 && lifeSpan <= 20) { animalsGrid.getField("status").setCanEdit(true); animalsGrid.getField("diet").setCanEdit(true); } if (lifeSpan > 20 && lifeSpan <= 50) { animalsGrid.getField("status").setCanEdit(true); animalsGrid.getField("diet").setCanEdit(false); animalsGrid.setEditValue(event.getRowNum(), "diet", (String) null); } if (lifeSpan > 50 && lifeSpan <= 100) { animalsGrid.getField("status").setCanEdit(false); animalsGrid.setEditValue(event.getRowNum(), "status", (String) null); animalsGrid.getField("diet").setCanEdit(true); } if (lifeSpan > 100) { animalsGrid.getField("status").setCanEdit(false); animalsGrid.setEditValue(event.getRowNum(), "status", (String) null); animalsGrid.getField("diet").setCanEdit(false); animalsGrid.setEditValue(event.getRowNum(), "diet", (String) null); } } }); animalsGrid.setFields(commonName, scientificName, lifeSpan, status, diet); animalsGrid.setSort(new SortSpecifier[] { new SortSpecifier(commonName.getName(), SortDirection.ASCENDING) }); animalsGrid.fetchData(new AdvancedCriteria(new Criterion("commonName", OperatorId.LESS_OR_EQUAL, "D"))); w.addItem(animalsGrid); IButton reloadBtn = new IButton("Reload data"); reloadBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { animalsGrid.invalidateCache(); } }); w.addItem(reloadBtn); w.show(); } private class LifeSpanLGF extends ListGridField { public LifeSpanLGF(String name, final ListGrid parentListGrid) { super(name); LinkedHashMap<Integer, String> valueMap = new LinkedHashMap<Integer, String>(); valueMap.put(1, "1 (edit both)"); valueMap.put(5, "5 (edit both)"); valueMap.put(10, "10 (edit both)"); valueMap.put(20, "20 (edit both)"); valueMap.put(50, "50 (edit status)"); valueMap.put(100, "100 (edit diet)"); valueMap.put(150, "150 (edit none)"); SelectItem si = new SelectItem(); si.setValueMap(valueMap); si.addChangedHandler(new com.smartgwt.client.widgets.form.fields.events.ChangedHandler() { @Override public void onChanged(com.smartgwt.client.widgets.form.fields.events.ChangedEvent event) { SC.logWarn("SelectItem ChangedEvent"); Integer lifeSpan = (Integer) event.getValue(); if (lifeSpan > 0 && lifeSpan <= 20) { parentListGrid.getField("status").setCanEdit(true); parentListGrid.getField("diet").setCanEdit(true); } if (lifeSpan > 20 && lifeSpan <= 50) { parentListGrid.getField("status").setCanEdit(true); parentListGrid.getField("diet").setCanEdit(false); parentListGrid.setEditValue(parentListGrid.getEditRow(), "diet", (String) null); } if (lifeSpan > 50 && lifeSpan <= 100) { parentListGrid.getField("status").setCanEdit(false); parentListGrid.setEditValue(parentListGrid.getEditRow(), "status", (String) null); parentListGrid.getField("diet").setCanEdit(true); } if (lifeSpan > 100) { parentListGrid.getField("status").setCanEdit(false); parentListGrid.setEditValue(parentListGrid.getEditRow(), "status", (String) null); parentListGrid.getField("diet").setCanEdit(false); parentListGrid.setEditValue(parentListGrid.getEditRow(), "diet", (String) null); } } }); LifeSpanLGF.this.setEditorProperties(si); LifeSpanLGF.this.setValueMap(valueMap); } } }[B][/B]
Please then change the lifespan of all shown animals to a value from the SelectItem.
If you do so like this
you'll see that if you start to edit rows, the desired effect (both, only status, only diet or none editable) is only there on the 2nd start of the row editor. The first start is always like the row edited before the current row.
So if you e.g. keep moving from "only status" to "only diet" rows back and forth (without doing any changes), always the wrong column is editable.
Additionally the ChangedHandler on the SelectItem does fire, but the effect of the change is not visible.
From the visual effect this is what I was seeing here, although I don't know if it is related.
Best regards
Blama
Comment