Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Tree Grid/List Grid not loading JSON data

    Hi,
    I'm trying load JSON data to ListGrid and I'm not seeing any records been listed.I'm seeing 15 records after executing eval.
    Please suggest on this.What i'm missing here.
    Code:
    public void onModuleLoad()
    	{
    
    		final ListGrid countryGrid = new ListGrid();
    
    		countryGrid.setWidth(400);
    		countryGrid.setHeight(224);
    		countryGrid.setShowAllRecords(true);
    		countryGrid.setData(loadData());
    		countryGrid.draw();
    	}
    
    	private ListGridRecord[] loadData()
    	{
    		String jsonString = "[{    \"continent\":\"North America\",    \"countryName\":\"United States\",    \"countryCode\":\"US\",    \"area\":9631420,    \"population\":298444215,    \"gdp\":12360000,    \"independence\":\"1776-07-04\",    \"government\":\"federal republic\",    \"government_desc\":2,    \"capital\":\"Washington, DC\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/United_states\"},{    \"continent\":\"Asia\",    \"countryName\":\"China\",    \"countryCode\":\"CH\",    \"area\":9596960,    \"population\":1313973713,    \"gdp\":8859000,    \"government\":\"Communist state\",    \"government_desc\":0,    \"capital\":\"Beijing\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/China\"},{    \"continent\":\"Asia\",    \"countryName\":\"Japan\",    \"countryCode\":\"JA\",    \"area\":377835,    \"population\":127463611,    \"gdp\":4018000,    \"government\":\"constitutional monarchy with parliamentary government\",    \"government_desc\":1,    \"capital\":\"Tokyo\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/Japan\"},{    \"continent\":\"Asia\",    \"countryName\":\"India\",    \"countryCode\":\"IN\",    \"area\":3287590,    \"population\":1095351995,    \"gdp\":3611000,    \"independence\":\"1947-08-15\",    \"government\":\"federal republic\",    \"government_desc\":2,    \"capital\":\"New Delhi\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/India\"},{    \"continent\":\"Europe\",    \"countryName\":\"Germany\",    \"countryCode\":\"GM\",    \"area\":357021,    \"population\":82422299,    \"gdp\":2504000,    \"independence\":\"1871-01-18\",    \"government\":\"federal republic\",    \"government_desc\":2,    \"capital\":\"Berlin\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/Germany\"},{    \"continent\":\"Europe\",    \"countryName\":\"United Kingdom\",    \"countryCode\":\"UK\",    \"area\":244820,    \"population\":60609153,    \"gdp\":1830000,    \"independence\":\"1801-01-01\",     \"government\":\"constitutional monarchy\",    \"government_desc\":1,    \"capital\":\"London\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/United_kingdom\"},{    \"continent\":\"Europe\",    \"countryName\":\"France\",    \"countryCode\":\"FR\",    \"area\":547030,    \"population\":60876136,    \"gdp\":1816000,    \"government\":\"republic\",    \"government_desc\":5,    \"capital\":\"Paris\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/France\"},{    \"continent\":\"Europe\",    \"countryName\":\"Italy\",    \"countryCode\":\"IT\",    \"area\":301230,    \"population\":58133509,    \"gdp\":1698000,    \"independence\":\"1861-03-17\",    \"government\":\"republic\",    \"government_desc\":5,    \"capital\":\"Rome\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/Italy\"},{    \"continent\":\"Asia\",    \"countryName\":\"Russia\",    \"countryCode\":\"RS\",    \"area\":17075200,    \"population\":142893540,    \"gdp\":1589000,    \"independence\":\"1991-08-24\",    \"government\":\"federation\",    \"government_desc\":3,    \"capital\":\"Moscow\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/Russia\"},{    \"continent\":\"South America\",    \"countryName\":\"Brazil\",    \"countryCode\":\"BR\",    \"area\":8511965,    \"population\":188078227,    \"gdp\":1556000,    \"independence\":\"1822-09-07\",    \"government\":\"federative republic\",    \"government_desc\":3,    \"capital\":\"Brasilia\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/Brazil\"},{    \"continent\":\"North America\",    \"countryName\":\"Canada\",    \"countryCode\":\"CA\",    \"area\":9984670,    \"population\":33098932,    \"gdp\":1114000,    \"independence\":\"1867-07-01\",    \"government\":\"constitutional monarchy with parliamentary democracy and federation\",    \"government_desc\":1,    \"capital\":\"Ottawa\",    \"member_g8\":true,    \"article\":\"http://en.wikipedia.org/wiki/Canada\"},{    \"continent\":\"North America\",    \"countryName\":\"Mexico\",    \"countryCode\":\"MX\",    \"area\":1972550,    \"population\":107449525,    \"gdp\":1067000,    \"independence\":\"1810-09-16\",    \"government\":\"federal republic\",    \"government_desc\":2,    \"capital\":\"Mexico (Distrito Federal)\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/Mexico\"},{    \"continent\":\"Europe\",    \"countryName\":\"Spain\",    \"countryCode\":\"SP\",    \"area\":504782,    \"population\":40397842,    \"gdp\":1029000,    \"independence\":\"1492-01-01\",    \"government\":\"parliamentary monarchy\",    \"government_desc\":4,    \"capital\":\"Madrid\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/Spain\"},{    \"continent\":\"Asia\",    \"countryName\":\"South Korea\",    \"countryCode\":\"KS\",    \"area\":98480,    \"population\":48846823,    \"gdp\":965300,    \"independence\":\"1945-08-15\",    \"government\":\"republic\",    \"government_desc\":5,    \"capital\":\"Seoul\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/South_korea\"},{    \"continent\":\"Asia\",    \"countryName\":\"Indonesia\",    \"countryCode\":\"ID\",    \"area\":1919440,    \"population\":245452739,    \"gdp\":865600,    \"independence\":\"1945-08-17\",    \"government\":\"republic\",    \"government_desc\":5,    \"capital\":\"Jakarta\",    \"member_g8\":false,    \"article\":\"http://en.wikipedia.org/wiki/Indonesia\"}]";
    		ListGridRecord[] records = jsonToRecords(jsonString);
    		SC.say("Count of records " + records.length);
    		return records;
    	}
    
    	public static native ListGridRecord[] jsonToRecords(String jsonString) /*-{
    		var json = eval(jsonString);		
    		return @com.smartgwt.client.widgets.grid.ListGrid::convertToListGridRecordArray(Lcom/google/gwt/core/client/JavaScriptObject;)(json);
    	}-*/;
    Thanks beforehand.

    #2
    Try countryGrid.setAutoFetchData(true)

    Comment


      #3
      Thanks for the reply.Below additional lines solved the issue and grid has been loaded with data
      Code:
      		ListGridField codeField = new ListGridField("countryCode", "Country", 128);
      		ListGridField nameField = new ListGridField("countryName", "Name", 128);
      		ListGridField capitalField = new ListGridField("capital", "Capital", 40);
      		
      		countryGrid.setFields(codeField,nameField,capitalField);

      Comment

      Working...
      X