Hi,
I'm using SmartGWT nightly build (2011-07-30) on Chrome 12.0.742.124 and Firefox 5.0 on Ubuntu 10.04 64bit.
I have a requirement where a table with filter headers may or may not have a summary row (or it can have 3) and as such setShowGridSummary is set dynamically after the component is drawn. This, however, breaks the listgrid headers by seemingly shifting the whole main table up by around 20 pixels.
In the following example I do this just before I fetch data for the table:
I'm using SmartGWT nightly build (2011-07-30) on Chrome 12.0.742.124 and Firefox 5.0 on Ubuntu 10.04 64bit.
I have a requirement where a table with filter headers may or may not have a summary row (or it can have 3) and as such setShowGridSummary is set dynamically after the component is drawn. This, however, breaks the listgrid headers by seemingly shifting the whole main table up by around 20 pixels.
In the following example I do this just before I fetch data for the table:
Code:
import java.util.ArrayList; import java.util.List; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.DataSourceField; import com.smartgwt.client.data.OperationBinding; import com.smartgwt.client.types.AutoFitWidthApproach; import com.smartgwt.client.types.DSOperationType; import com.smartgwt.client.types.DSProtocol; import com.smartgwt.client.types.FieldType; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.widgets.IButton; 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.VLayout; public class FilterAndSummaryGrid extends VLayout { private final ListGrid table; public FilterAndSummaryGrid(){ super(5); setWidth("50%"); setHeight("50%"); IButton fetchButton = new IButton("Fetch Data", new ClickHandler() { public void onClick(ClickEvent event) { handleFetch(); } }); addMember(fetchButton); table = new ListGrid(); table.setAlternateRecordStyles(true); table.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH); table.setHeaderHeight(40); table.setShowGridSummary(false); table.setShowFilterEditor(true); table.setDataSource(new TableDataSource()); ListGridField[] fields = new ListGridField[10]; for(int i=0;i<10;i++){ fields[i] = new ListGridField("Field"+i); fields[i].setType(ListGridFieldType.FLOAT); } table.setFields(fields); addMember(table); } private void handleFetch() { table.setData(new ListGridRecord[0]); table.setShowGridSummary(true); table.fetchData(table.getFilterEditorCriteria()); } private static class TableDataSource extends DataSource { private TableDataSource(){ setID("TableDatasource1"); setClientOnly(true); setupOperationBindings(); setPrimaryKey(); } private void setPrimaryKey() { DataSourceField keyField = new DataSourceField("IdNum", FieldType.BINARY); keyField.setPrimaryKey(true); keyField.setHidden(true); addField(keyField); } private void setupOperationBindings() { OperationBinding fetch = new OperationBinding(DSOperationType.FETCH, ""); fetch.setDataProtocol(DSProtocol.CLIENTCUSTOM); OperationBinding add = new OperationBinding(DSOperationType.ADD, ""); add.setDataProtocol(DSProtocol.CLIENTCUSTOM); OperationBinding update = new OperationBinding(DSOperationType.UPDATE, ""); update.setDataProtocol(DSProtocol.CLIENTCUSTOM); OperationBinding remove = new OperationBinding(DSOperationType.REMOVE, ""); remove.setDataProtocol(DSProtocol.CLIENTCUSTOM); setOperationBindings(fetch, add, update, remove); } protected Object transformRequest(DSRequest request) { if (request.getOperationType() == DSOperationType.FETCH) handleFetch(request); return super.transformRequest(request); } private void handleFetch(DSRequest request) { List<ListGridRecord> records = new ArrayList<ListGridRecord>(); for(int i=0;i<5000;i++){ ListGridRecord record = new ListGridRecord(); for(int j=0;j<10;j++){ record.setAttribute("Field"+j, Math.random()); } records.add(record); } DSResponse response = new DSResponse(); response.setData(records.toArray(new ListGridRecord[0])); processResponse(request.getRequestId(), response); } } }
Code:
public void onModuleLoad() { new FilterAndSummaryGrid().draw(); }
Comment