Hi,
Our listgrid displays columns that contain image and text and we need to refresh the data every 10 seconds (see EPollingTimer). There is no such ListGridFieldType, and we need to use createRecordComponent to create the custom widget.
When we don't use custom component in "createRecordComponent", listgrid's performance is ok. I can scroll up and down the table. But when we use createRecordComponent and we create a canvas that contains an image and a label, the table stops responding (EImageWithText). Can you explain what is wrong and is it possible to improve the performance. We use SmartGWT 2.5, Firefox and IE browsers.
Thanks,
Olga.
Our listgrid displays columns that contain image and text and we need to refresh the data every 10 seconds (see EPollingTimer). There is no such ListGridFieldType, and we need to use createRecordComponent to create the custom widget.
When we don't use custom component in "createRecordComponent", listgrid's performance is ok. I can scroll up and down the table. But when we use createRecordComponent and we create a canvas that contains an image and a label, the table stops responding (EImageWithText). Can you explain what is wrong and is it possible to improve the performance. We use SmartGWT 2.5, Firefox and IE browsers.
Thanks,
Olga.
Code:
package gwt.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.Timer; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.data.ResultSet; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.FetchMode; import com.smartgwt.client.types.ImageStyle; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.types.Overflow; import com.smartgwt.client.types.PromptStyle; import com.smartgwt.client.types.TextMatchStyle; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.util.Page; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.grid.CellFormatter; 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; public class EDebugTable implements EntryPoint { ListGrid listGrid = new EListGrid(); @Override public void onModuleLoad() { Page.setAppImgDir(EFileUtils.getImagesDir()); listGrid.setShowRecordComponents(true); listGrid.setShowRecordComponentsByCell(true); RPCManager.setPromptStyle(PromptStyle.CURSOR); DataSource dataSource = ItemSupplyXmlDS.getInstance(); ListGridField rowNum = new ListGridField("itemNum", "Item No."); rowNum.setWidth(65); rowNum.setCellFormatter(new CellFormatter() { @Override public String format(Object aValue, ListGridRecord aRecord, int aRowNum, int aColNum) { return aRowNum +""; } }); ListGridField itemName = new ListGridField("itemName", 100); ListGridField sku = new ListGridField("SKU", 100); ListGridField description = new ListGridField("description", 150); ListGridField category = new ListGridField("category", 100); ListGridField units = new ListGridField("units", 100); ListGridField unitCost = new ListGridField("unitCost", 100); unitCost.setType(ListGridFieldType.FLOAT); ListGridField inStock = new ListGridField("inStock", 100); inStock.setType(ListGridFieldType.BOOLEAN); listGrid.setWidth100(); listGrid.setHeight100(); listGrid.setAutoFetchData(true); listGrid.setDataSource(dataSource); listGrid.setFields(rowNum, itemName, sku, description, category, units, unitCost); EPollingTimer timer = new EPollingTimer(); timer.scheduleRepeating(10000); listGrid.draw(); } class EListGrid extends ListGrid { @Override protected Canvas createRecordComponent(ListGridRecord aRecord, Integer aColNum) { EImageWithText imageWithText = new EImageWithText(); imageWithText.mText.setContents("Text!!!!"); imageWithText.mImage.setSrc("alarm-blue_10.gif"); return imageWithText; } } private static final int REFRESH_ROW_OFFSET = 15; class EImageWithText extends HLayout { private Label mText = new Label(); private Img mImage = new Img(); public EImageWithText() { setLayoutAlign(VerticalAlignment.CENTER); setAlign(Alignment.LEFT); // text alignment inside label mText.setAlign(Alignment.LEFT); mText.setWidth100(); mText.setHeight100(); mImage.setImageType(ImageStyle.NORMAL); mImage.setAutoHeight(); mImage.setAutoWidth(); addMember(mImage); addMember(mText); setOverflow(Overflow.HIDDEN); setMargin(0); setHeight(20); setBackgroundColor("pink"); } } class EPollingTimer extends Timer { @Override public void run() { final Integer row[] = listGrid.getVisibleRows(); final DSRequest request = new DSRequest(); request.setStartRow(Math.max(0, row[0] - REFRESH_ROW_OFFSET)); request.setEndRow(row[1] + REFRESH_ROW_OFFSET); request.setSortBy(listGrid.getSort()); request.setTextMatchStyle(TextMatchStyle.SUBSTRING); final DataSource ds = listGrid.getDataSource(); ds.setShowPrompt(false); ds.fetchData(listGrid.getCriteria(), new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { final ResultSet resultset = new ResultSet(); resultset.setDataSource(ds); resultset.setCriteria(listGrid.getCriteria()); resultset.setFetchMode(FetchMode.PAGED); resultset.setInitialLength(response.getTotalRows()); Record[] responseData = response.getData(); Record[] initialData = new Record[response.getEndRow()+1]; for (int i = 0; i <= response.getEndRow(); i++) { if (i < response.getStartRow()) { initialData[i] = null; } else { initialData[i] = responseData[i-response.getStartRow()]; } } resultset.setInitialData(initialData); listGrid.setData(resultset); } }, request); } } }
Comment