Results 1 to 5 of 5

Thread: Json data does not load into the grid

  1. #1
    Sencha User
    Join Date
    Mar 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default Json data does not load into the grid

    Hi,

    I am trying to connect to a WCF(ADO.NET) Data Service that outputs Json Data in the following format:

    {
    "d" : [
    {
    "__metadata": {
    "uri": "http://10.80.247.25/ODataCustomService.svc/Graph(1)", "type": "PL_TestBed.Coordinates"
    }, "week": 1, "value": 25.618189831552186
    }, {
    "__metadata": {
    "uri": "http://10.80.247.25/ODataCustomService.svc/Graph(2)", "type": "PL_TestBed.Coordinates"
    }, "week": 2, "value": 77.338295936276339
    }
    ]}
    The code I have written to pull and dispay the data in the grid is as follows -
    Code:
     
    Ext.onReady(function () {
    var ds = new Ext.data.Store({
    proxy: new Ext.data.ScriptTagProxy({
    url: 'http://10.80.247.25/ODataCustomService.svc/Graph?$format=json'
    }),
    reader: new Ext.data.JsonReader({
    root: 'd',
    id: 'week'
    }, [
    { name: 'week', mapping: 'week' },
    { name: 'value', mapping: 'value' }
    ])
    });
    // load the store immeditately
    ds.load();
     
    var graphColumns = [
    { header: "week", width: 40, sortable: true, dataIndex: 'week' },
    { header: "value", width: 100, sortable: true, dataIndex: 'value' }
    ];
    ?
    // Create a typical GridPanel with RowEditor plugin
    var userGrid = new Ext.grid.GridPanel({
    renderTo: 'user-grid',
    iconCls: 'icon-grid',
    frame: true,
    title: 'Graph',
    height: 300,
    store: ds,
    columns: graphColumns,
    viewConfig: {
    forceFit: true
    }
    });
    });
    
    The data is not being loaded into the store/grid. In Firefox its not throwing any error and in firebug I see the GET being successfully called and the data being returned as response. However, I beleive the data is not getting loaded into the data store.

    I get the following error in IE -

    Webpage error details
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)
    Timestamp: Mon, 14 Mar 2011 19:17:19 UTC

    Message: Expected ';'
    Line: 2
    Char: 5
    Code: 0
    URI: http://10.80.247.25/ODataCustomServi...tcCallback1001

    Whats going on here? I tried using some other php site that returns json data and it works fine.

    For example this works fine -http://extjs.com/forum/topics-remote.php'

    Code:
    Ext.onReady(function () {
    var ds = new Ext.data.Store({
    proxy: new Ext.data.ScriptTagProxy({
    url: 'http://extjs.com/forum/topics-remote.php'
    ?
    }),
    reader: new Ext.data.JsonReader({
    root: 'topics',
    id: 'post_id'
    }, [
    { name: 'post_id', mapping: 'post_id' },
    { name: 'topic_title', mapping: 'topic_title' }
    ])
    });
    ?
    ds.load({ params: { start: 0, limit: 20, forumId: 4} });
    var graphColumns = [
    { header: "post_id", width: 40, sortable: true, dataIndex: 'post_id' },
    { header: "topic_title", width: 100, sortable: true, dataIndex: 'topic_title' }
    ];
    ?
    ?
    var userGrid = new Ext.grid.GridPanel({
    renderTo: 'user-grid',
    iconCls: 'icon-grid',
    frame: true,
    title: 'Graph',
    height: 300,
    store: ds,
    columns: graphColumns,
    viewConfig: {
    forceFit: true
    }
    });
    });
    
    Please advice as to whats wrong in the first example, its urgent.

    Thanks,
    PK

  2. #2
    Sencha User brittongr's Avatar
    Join Date
    Jun 2007
    Location
    Panama
    Posts
    109
    Vote Rating
    3
      0  

    Default

    You are not returning:

    Code:
    "success":true,
    It should be in the same level as "d"
    Greivin Britton

    My Extensions:
    Ext.ux.NumericField: Number field with support for currencySymbol, thousand separator, international...
    Ext.ux.PagerSizeSelector: A plugin that allows the change page size with just one click.
    Ext.ux.FieldAccess: A plugin to let the user know which fields are editable.

  3. #3
    Sencha User
    Join Date
    Mar 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Thanks But my question is
    How is it working with the other service then? Even http://extjs.com/forum/topics-remote.php'

    does not have success:'true'

    If i do not have access to the server side code, how can I modify the client code to accomodate the additional parameter?




    Quote Originally Posted by brittongr View Post
    You are not returning:

    Code:
    "success":true,
    It should be in the same level as "d"

  4. #4
    Sencha User
    Join Date
    Mar 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Thanks I just found the solution to my problem.

    Read this -http://stackoverflow.com/questions/4...property-names

    In my service I just had to return the callback along with data and it worked fine.

    Quote Originally Posted by brittongr View Post
    You are not returning:

    Code:
    "success":true,
    It should be in the same level as "d"

  5. #5
    Sencha User brittongr's Avatar
    Join Date
    Jun 2007
    Location
    Panama
    Posts
    109
    Vote Rating
    3
      0  

    Default

    Great! Thanks for letting me to know...
    Greivin Britton

    My Extensions:
    Ext.ux.NumericField: Number field with support for currencySymbol, thousand separator, international...
    Ext.ux.PagerSizeSelector: A plugin that allows the change page size with just one click.
    Ext.ux.FieldAccess: A plugin to let the user know which fields are editable.

Similar Threads

  1. Having a Grid inside a Form and load data from one JSON data source!
    By behrooz_a in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 6 Jan 2011, 3:26 AM
  2. Load JSON data into a Grid
    By abcdef in forum Ext 3.x: Help & Discussion
    Replies: 13
    Last Post: 3 Apr 2010, 11:12 AM
  3. how can i load data from json to grid
    By anoop abbot in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 16 Apr 2009, 1:17 AM
  4. Load returned json data into a grid.
    By whdanj in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 15 Apr 2009, 5:26 AM
  5. Steps to load JSON/XML data into a Grid?
    By jpnet in forum Community Discussion
    Replies: 1
    Last Post: 11 Dec 2008, 8:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •