Welcome Guest, Not a member yet? Register   Sign In
EXT JS - Can´t get data from a controller - Probably simple
#1

[eluser]PoetaWD[/eluser]
Hello,
I am new with EXT and CI.
Yesterday I started studying how to use both, together, in a application.

I am pretty sure some of you work with ext, Can you point me in the right direction ?

I am also using Datamapper library to help…

Here is my Controller:
Code:
function js_list()
    {
        $obj = new Area();
        $obj->get();
        
        $objetos = $obj->all;
        
        $rows = 0;
    
        foreach($objetos as $row)
        {
            $item = Array("Id" => $row->id,
                          "stNome" => $row->stNome);
    
            $itemList[] = $item;
            
            $rows = $rows + 1;
        }
        $data = json_encode($itemList);
    
        echo '({"total":"' . $rows . '","results":' . $data . '})';
    }

It generates a JSON code like this:
Code:
({"total":"3","results":[{"Id":"1","stNome":"Direito Civil"},{"Id":"2","stNome":"Direito Penal"},{"Id":"3","stNome":"Direito de Software"}]})
Here is my ext grid:
Code:
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* [email protected]
* http://www.extjs.com/license
*/
Ext.onReady(function(){

    var store = new Ext.data.JsonStore({
        // store configs
        autoDestroy: true,
        url: 'http://localhost/sgp/index.php?c=careas&m=js_list',
        storeId: 'myStore',
        // reader configs
        root: 'results',
        idProperty: 'Id',  
        fields: ['Id', 'stNome']
    });

    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {header: "Id", width: 120, dataIndex: 'Id', sortable: true},
            {header: "stNome", width: 180, dataIndex: 'stNome', sortable: true},
        ],
        renderTo:'example-grid',
        width:300,
        height:200
    });

    store.load();
});

The weird is that if I access the js_list controller, copy the code, create another file called data.php and point the js to load the data from it, it will work just fine… that means that my JSON is correct but the JS is not getting data from the controller function…

Does anyone have any idea on how to get this working ?

Thanks
#2

[eluser]PoetaWD[/eluser]
Just realized that I had the profiler turned on... that is why data was not loaded...

I am feeling sooo DUMB ... Tongue

At least it works !

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB