Hello,
I am using smartgwt 2.4.
I have been trying out the offline preferences functionality which is great. I have come across a problem however.
I have a grid which I have added the offline functionality to. This works fine.
I also would like to be able to filter the data in the columns so add the filtering functionality.
Now when I view my grid, the columns of data are in the correct places but the column names have reverted to the original places and no longer relate to the data.
You can see this by adding the following lines to the showcase example as I have below countryGrid.setShowFilterEditor(true), countryGrid.setFilterOnKeypress(true);
I don't see any errors in any of the logs.
Here is the code which generates the error
Could you please have a look and see if I am doing something wrong?
Thank you very much,
Jeni
I am using smartgwt 2.4.
I have been trying out the offline preferences functionality which is great. I have come across a problem however.
I have a grid which I have added the offline functionality to. This works fine.
I also would like to be able to filter the data in the columns so add the filtering functionality.
Now when I view my grid, the columns of data are in the correct places but the column names have reverted to the original places and no longer relate to the data.
You can see this by adding the following lines to the showcase example as I have below countryGrid.setShowFilterEditor(true), countryGrid.setFilterOnKeypress(true);
I don't see any errors in any of the logs.
Here is the code which generates the error
Code:
public class TestPanel extends Canvas { public TestPanel(){ VLayout layout = new VLayout(15); layout.setWidth(650); layout.setAutoHeight(); final ListGrid countryGrid = new ListGrid(); countryGrid.setShowFilterEditor(true); countryGrid.setFilterOnKeypress(true); countryGrid.setLeaveScrollbarGap(true); countryGrid.setCanFreezeFields(false); countryGrid.setCanGroupBy(false); countryGrid.setWidth100(); countryGrid.setHeight(224); countryGrid.setDataSource(CountryXmlDS.getInstance()); countryGrid.setAutoFetchData(true); //allow users to add formula and summary fields //accessible in the grid header context menu countryGrid.setCanAddFormulaFields(true); countryGrid.setCanAddSummaryFields(true); ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 50); countryCodeField.setAlign(Alignment.CENTER); countryCodeField.setType(ListGridFieldType.IMAGE); countryCodeField.setImageURLPrefix("flags/16/"); countryCodeField.setImageURLSuffix(".png"); countryCodeField.setCanSort(false); ListGridField nameField = new ListGridField("countryName", "Country"); ListGridField capitalField = new ListGridField("capital", "Capital"); ListGridField populationField = new ListGridField("population", "Population"); populationField.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; try { NumberFormat nf = NumberFormat.getFormat("0,000"); return nf.format(((Number) value).longValue()); } catch (Exception e) { return value.toString(); } } }); ListGridField areaField = new ListGridField("area", "Area (kmē)"); areaField.setType(ListGridFieldType.INTEGER); areaField.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; String val = null; try { NumberFormat nf = NumberFormat.getFormat("0,000"); val = nf.format(((Number) value).longValue()); } catch (Exception e) { return value.toString(); } return val + "kmē"; } }); countryGrid.setFields(countryCodeField, nameField, capitalField, populationField, areaField); ToolStripButton formulaButton = new ToolStripButton("Formula Builder", "crystal/oo/sc_insertformula.png"); formulaButton.setAutoFit(true); formulaButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.addFormulaField(); } }); ToolStripButton summaryBuilder = new ToolStripButton("Summary Builder", "crystal/16/apps/tooloptions.png"); summaryBuilder.setAutoFit(true); summaryBuilder.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.addSummaryField(); } }); ToolStripButton savePreference = new ToolStripButton("Persist State", "silk/database_gear.png"); savePreference.setAutoFit(true); savePreference.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String viewState = countryGrid.getViewState(); Offline.put("exampleState", viewState); SC.say("Preferences persisted."); } }); //toolstrip to attach to the country grid ToolStrip countryGridToolStrip = new ToolStrip(); countryGridToolStrip.setWidth100(); countryGridToolStrip.addFill(); countryGridToolStrip.addButton(formulaButton); countryGridToolStrip.addButton(summaryBuilder); countryGridToolStrip.addSeparator(); countryGridToolStrip.addButton(savePreference); VLayout countryGridLayout = new VLayout(0); countryGridLayout.setWidth(650); countryGridLayout.addMember(countryGridToolStrip); countryGridLayout.addMember(countryGrid); layout.addMember(countryGridLayout); final String previouslySavedState = (String) Offline.get("exampleState"); System.out.println(previouslySavedState); if (previouslySavedState != null) { countryGrid.addDrawHandler(new DrawHandler() { @Override public void onDraw(DrawEvent event) { //restore any previously saved view state for this grid countryGrid.setViewState(previouslySavedState); } }); } addChild(layout); }
Thank you very much,
Jeni
Comment