Hi Isomorphic,
please see this 5.1p based testcase (v10.1p_2017-08-20).
As you can see in the video (wait a bit, slow because of FF26 dev mode, but happens also compiled in GC60), the buttons are not updated until the data is reloaded via invalidateCache(). This does only happen in a grouped ListGrid.
Best regards
Blama
please see this 5.1p based testcase (v10.1p_2017-08-20).
As you can see in the video (wait a bit, slow because of FF26 dev mode, but happens also compiled in GC60), the buttons are not updated until the data is reloaded via invalidateCache(). This does only happen in a grouped ListGrid.
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.Version; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.types.RecordComponentPoolingMode; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; 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.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; public class BuiltInDS extends VLayout implements EntryPoint { private IButton recreateBtn; private DataSource ds = DataSource.get("employees"); 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(); } }); setWidth100(); setHeight100(); recreateBtn = new IButton("Recreate"); recreateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new MyWindow().show(); } }); addMember(recreateBtn); new MyWindow().show(); draw(); } private class MyWindow extends Window { public MyWindow() { setWidth("95%"); setHeight("95%"); setMembersMargin(0); setModalMaskOpacity(70); setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")"); setTitle("RecordComponent problem after data update and if-condition-change in grouped ListGrid" + getTitle()); setShowMinimizeButton(false); setIsModal(true); setShowModalMask(true); centerInPage(); final MyListGrid employeesGrid = new MyListGrid(ds); employeesGrid.setWidth(500); employeesGrid.setHeight(200); employeesGrid.setShowRecordComponents(true); employeesGrid.setShowRecordComponentsByCell(true); employeesGrid.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE); employeesGrid.setPoolComponentsPerColumn(true); employeesGrid.setRecordComponentHeight(20); ListGridField employeeId = new ListGridField("EmployeeId"); employeeId.setHidden(true); ListGridField name = new ListGridField("Name"); ListGridField gender = new ListGridField("Gender"); ListGridField salary = new ListGridField("Salary"); ListGridField salary5k = new ListGridField("SALARY5K"); salary5k.setWidth(130); ListGridField salary10k = new ListGridField("SALARY10K"); salary10k.setWidth(130); employeesGrid.setFields(employeeId, name, gender, salary, salary5k, salary10k); employeesGrid.setGroupByField(gender.getName()); employeesGrid.setSortField(name.getName()); employeesGrid.fetchData(new AdvancedCriteria(name.getName(), OperatorId.GREATER_OR_EQUAL, "R")); HLayout buttonsLayout = new HLayout(5) { { setHeight(25); setPadding(5); setAlign(Alignment.LEFT); IButton salary5kButton = new IButton("Set salary 5000"); salary5kButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (employeesGrid.getSelectedRecord() != null) { for (ListGridRecord r : employeesGrid.getSelectedRecords()) { r.setAttribute("Salary", 5000); ds.updateData(r); } } } }); addMembers(salary5kButton); IButton salary10kButton = new IButton("Set salary 10000"); salary10kButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (employeesGrid.getSelectedRecord() != null) { for (ListGridRecord r : employeesGrid.getSelectedRecords()) { r.setAttribute("Salary", 10000); ds.updateData(r); } } } }); addMembers(salary10kButton); IButton reloadButton = new IButton("Reload"); reloadButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { employeesGrid.invalidateCache(); } }); addMembers(reloadButton); } }; addItem(employeesGrid); addItem(buttonsLayout); } } private class MyListGrid extends ListGrid { public MyListGrid(DataSource dataSource) { super(dataSource); } @Override protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) { return updateRecordComponent(record, colNum, null, true); } @Override public Canvas updateRecordComponent(final ListGridRecord record, Integer colNum, Canvas component, boolean recordChanged) { String fieldName = this.getFieldName(colNum); if (fieldName.equals("SALARY10K") && record.getAttribute("Salary") != null && record.getAttributeAsInt("Salary") == 10000) { if (component != null) { MyButton myButton = (MyButton) component; myButton.setListGridRecord(record); return myButton; } else { return new MyButton(record); } } else if (fieldName.equals("SALARY5K") && record.getAttribute("Salary") != null && record.getAttributeAsInt("Salary") == 5000) { if (component != null) { MyButton2 myButton = (MyButton2) component; myButton.setListGridRecord(record); return myButton; } else { return new MyButton2(record); } } else { return null; } } } private class MyButton extends IButton { private ListGridRecord listGridRecord; public void setListGridRecord(ListGridRecord r) { this.listGridRecord = r; } public MyButton(ListGridRecord r) { super("Salary 10k"); this.listGridRecord = r; setShowDown(false); setShowRollOver(false); setLayoutAlign(Alignment.CENTER); setWidth(100); setHeight(20); addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { SC.say("Show name clicked for: " + MyButton.this.listGridRecord.getAttribute("Name")); } }); } } private class MyButton2 extends IButton { private ListGridRecord listGridRecord; public void setListGridRecord(ListGridRecord r) { this.listGridRecord = r; } public MyButton2(ListGridRecord r) { super("Salary 5k"); this.listGridRecord = r; setShowDown(false); setShowRollOver(false); setLayoutAlign(Alignment.CENTER); setWidth(100); setHeight(20); addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { SC.say("Show name clicked for: " + MyButton2.this.listGridRecord.getAttribute("EmployeeId")); } }); } } }
Blama
Comment