PDA

View Full Version : [Solved] Return data from symfony function



atze
19 Jan 2010, 11:03 AM
Hi,

I dont now how to property return data from symfony function and how to use this in store.


/**
* Test
*
* @extdirect-enable
* @extdirect-len 0
*
*/
public function executeTest()
{
$data = array (
array ('3m Co',71.72),
array ('Alcoa Inc',29.01),
array ('Wal-Mart Stores, Inc.',45.45)
);

$this->result = array('resultArray' => $data, 'totalCount' => count($data));
return sfView::SUCCESS;
}Response - date return as object:

{"type":"rpc","tid":2,"action":"portal","method":"test","result":{"resultArray":[["3m Co",71.72],["Alcoa Inc",29.01],["Wal-Mart Stores, Inc.",45.45]],"totalCount":3}}Store:

var store = new Ext.data.DirectStore({
directFn: myApp.portal.test,
root: 'resultArray', // ???
totalProperty: 'totalCount', // ???
fields: [
{name: 'company'},
{name: 'price', type: 'float'}
]
});

var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{id:'company',header: 'Company', dataIndex: 'company'},
{header: 'Price', dataIndex: 'price'}
],
height: 350,
width: 600,
});Grid is empty. Only rows no data. What is wrong?

cerad
20 Jan 2010, 10:13 AM
There is a bug in Ext.data.DataReader in that it ignores the root: name argument.
http://www.extjs.com/forum/showthread.php?t=84398

The bug report has a status of UNKNOWN so it's unclear if this will be addressed or if it works as intended. Certainly not fixed in 3.1.1-beta

atze
28 Jan 2010, 9:42 AM
Hi, i have working example:

/**
* Test
*
* @extdirect-enable
* @extdirect-len 0
*
*/
public function executeTest()
{
echo $this->getRequestParameter('sort');
echo $this->getRequestParameter('dir');

$pager = DbFinder::from('Portal')->paginate(1,3);
$resultArray = array();

foreach($pager->getResults() as $res)
$resultArray[] = $res->toArray();

$this->result = array('resultArray' => $resultArray, 'totalCount' => $pager->getNbResults());
return sfView::SUCCESS;
}
{"type":"rpc","tid":4,"action":"portal","method":"test","result":{"resultArray":[{"Id":1,"Name":"Gory"},{"Id":2,"Name":"Morze"},{"Id":3,"Name":"Jura"}],"totalCount":3}}
var store = new Ext.data.DirectStore({
directFn: myApp.portal.test,
autoLoad: true,
idProperty: 'id',
totalProperty: 'totalCount',
root: 'resultArray',
fields: [
{name: 'Id'},
{name: 'Name'}
],
sortInfo: {
field: 'id',
direction: 'DESC'
},
remoteSort: true
});

// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: 'ID', width: 160, sortable: true, dataIndex: 'Id'},
{header: 'Name', width: 75, sortable: true, dataIndex: 'Name'}
],
stripeRows: true,
frame: true,
height: 350,
width: 960,
title: 'Portal',
columnLines: true
});
This works. I use remoteSort, but POST not send 'dir' and 'sort' value.

{"action":"portal","method":"test","data":null,"type":"rpc","tid":3}What is wrong?

atze
29 Jan 2010, 9:34 AM
I'm stupid.


/**
* Test
*
* @extdirect-enable
* @extdirect-len 2 <------------- before 0, no post data
*
*/Solved