Results 1 to 5 of 5

Thread: What is wrong with json format ?

  1. #1

    Default What is wrong with json format ?

    Hi everybody,
    I have a little problem.

    very simple window with ext 3 with grid:
    Code:
    var store = new Ext.data.Store({ mode:'remote', root:"rows", totalProperty:'total',
    reader: new Ext.data.JsonReader({}, ['ID']), url: 'ajax.store.kh.php', fields: [ {name: 'ID', type: 'int'}//, ] }); store.load();
    var grid = new Ext.grid.GridPanel({ store: store, mode:'remote', columns: [ {id:'ID',header: "ID", width: 160, sortable: true, dataIndex: 'ID'}//, ], stripeRows: true, title:'Klienci', bbar: new Ext.PagingToolbar({ pageSize: 5, store: store, displayInfo: true }) });
    php script generating output is ok:

    Code:
    $o = array( "success"=>true, "total"=>"2000", // temporary seted to const value "rows"=>$arr // data array );
    echo json_encode($o);
    answer in firebug is

    {"success":true,"total":"2000","rows":[{"ID":1509},{"ID":1497},{"ID":1496},{"ID":1495},
    {"ID":1494}]}

    I see grid with column ID and with calculated pages but without data.


    if I change php to echo only array with data:

    Code:
    echo json_encode($arr);
    


    grid is diplayed ok.


    What is wrong ? How to setup paging ?

    Best regards
    Jabba

  2. #2
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    there is no property mode for store or grid, also JsonReader is configured wrong. Consult the API, there is a sample also.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  3. #3
    Sencha User rbraddy's Avatar
    Join Date
    Jul 2009
    Location
    Houston, TX
    Posts
    144

    Default

    Jabba,

    Been down this road... ExtJS requires a specially-formed JSON string. Here's an example of one that works for me with my app:

    {"project":[{"answers":"","name":"WinningWare QuickLaunch","email":"","created_at":"2009-07-03 03:44:06 UTC","projectstatus":"","updated_at":"2009-07-03 03:44:06 UTC","account_id":"1","id":"1","projecttype":"0"},
    {"answers":"","name":"Precision Marketing System","email":"","created_at":"2009-07-03 04:31:00 UTC","projectstatus":"","updated_at":"2009-07-03 04:31:00 UTC","account_id":"1","id":"5","projecttype":"0"}],
    "results":"15"}

    If you're seeing the ID column in the grid, it's working, but you need to define the rest of your data fields (columns).

    Hope that helps.

    Rick

  4. #4
    Sencha User
    Join Date
    Jan 2008
    Location
    Maryville, IL, US
    Posts
    288

    Default

    success flag is not required (a failure is returning incorrect JSON or, sometimes, 0 rows).

    The following PHP code is sufficient for your needs.
    Code:
            $total = 2000 ; //should be total result from query
            // loop through query returning selected rows into $array based on $start and $limit passed from PagingToolbar
    
    	$retval = array( "results" => $total, "rows" => $array ) ;
            echo json_encode( $retval ) ;
    Also, pay attention to steffan's comments about config options on the store and grid.

  5. #5

    Default

    thanks its working now.

    missing properties in JsonReader was a key.

    Jabba

Posting Permissions

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