Hi, I've run across a problem when trying to use both expanding rows and the grid cell widgets. I can expand the row but it appears that it will not collapse.
Here is my code:
Any ideas on how I can get this to work? Thanks.
Here is my code:
Code:
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.*; import com.smartgwt.client.data.*; import com.smartgwt.client.data.fields.DataSourceIntegerField; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; 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.VLayout; public class TestCase implements EntryPoint { public void onModuleLoad() { final ListGrid listGrid = new ListGrid(){ @Override protected Canvas createRecordComponent(ListGridRecord record, Integer colNum){ String fieldName = getFieldName(colNum); if(fieldName.equals("info")){ return new IButton("Info"); } return null; } @Override protected Canvas getExpansionComponent(final ListGridRecord record) { VLayout layout = new VLayout(5); layout.setPadding(5); Label l = new Label("Expanded row"); layout.addMember(l); return layout; } }; listGrid.setWidth(500); listGrid.setHeight(300); ListGridField lastname = new ListGridField("lastname", "Last Name"); ListGridField firstname = new ListGridField("firstname","First Name"); ListGridField mi = new ListGridField("mi", "MI"); ListGridField info = new ListGridField("info", "Info"); listGrid.setFields(lastname, firstname, mi, info); listGrid.setShowRecordComponents(true); listGrid.setShowRecordComponentsByCell(true); listGrid.setCanExpandRecords(true); TestDataSource ds = new TestDataSource(); listGrid.setDataSource(ds); listGrid.fetchData(); listGrid.draw(); } public class TestDataSource extends DataSource { public TestDataSource(){ setClientOnly(true); DataSourceField pk = new DataSourceIntegerField("pk"); pk.setHidden(true); pk.setPrimaryKey(true); DataSourceField field = new DataSourceTextField("lastname"); addField(field); field = new DataSourceTextField("firstname"); addField(field); field = new DataSourceTextField("mi"); addField(field); createRecord(1,"Smith", "John", "A"); createRecord(2,"Smith", "Dave", "B"); createRecord(3,"Smith", "Pat", "C"); createRecord(4,"Jones", "Jim", "D"); createRecord(5,"Jones", "Mary", "E"); createRecord(6,"Johnson", "Paul", "F"); createRecord(7,"Brown", "Ed", "G"); } private void createRecord(int id, String last, String first, String mi){ ListGridRecord record = new ListGridRecord(); record.setAttribute("id", id); record.setAttribute("lastname", last); record.setAttribute("firstname", first); record.setAttribute("mi", mi); addData(record); } } }
Comment