PDA

View Full Version : Grid doesn't understand totalProperty



mlcaraldi
15 May 2014, 9:52 AM
Hello there! How are you guys?
I'm using EXT 4.2 and it's MVC architecture.

I have a View with a grid which is populated by a Store using a JSON proxy. This grid does have a "pagingToolbar" docked at it's top. I have "pageSize" defined to "25" on my grid, and "limit" and "pageSize" also defined to "25" on my Store. Somehow, the grid don't recognize the "totalProperty" value from my reader. I can confirm that JSON's values are correct through Firebug, but my grid's "displayMsg" keep displaying "1 - 25 from 25", when my JSON returns "1880" as it's "total" value. As a result of this problem, I'm not able to navigate through pages...

Do you guys have any ideia on what's going on? I'll post some codes below.

Store:

Ext.define('MyApp.store.Empresas', {
extend: 'Ext.data.Store',

model: 'MyApp.model.Empresas',
start: 0,
limit: 25,
pageSize: 25,
autoLoad: true,

proxy: {
type: 'ajax',
api: {
read: 'resources/data/empresas/ajx_lista_empresas.php',
update: 'resources/data/empresas/ajx_update_empresas.php',
create: 'resources/data/empresas/ajx_create_empresas.php',
destroy: 'resources/data/empresas/ajx_destroy_empresas.php'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
totalProperty: 'total'
},
//writer: {
// type: 'json',
// root: 'data',
// encode: true
//}
}
});

pagingToolbar definition:

{
dock: 'top',
xtype: 'pagingtoolbar',
store: 'Empresas',
pageSize: 25,
displayInfo: true,
displayMsg: 'Registros {0} - {1} de {2}',
emptyMsg: 'Sem Registros'
}

Firebug's JSON ;
49016
(I had to hide somethings because this is real data, but you can see the "total" value).

jsakalos
15 May 2014, 10:18 AM
total looks like object if Firebug. It should be number. I have a workable paging grid here: http://extjs.eu/examples/#writable-grid

mlcaraldi
15 May 2014, 10:24 AM
total looks like object if Firebug. It should be number. I have a workable paging grid here: http://extjs.eu/examples/#writable-grid

Thank you for your answer! You were right!
With a little help from a friend, looking deeper on my code, I realized that the problem was on my PHP... Just needed to specify the correct array position on this:

Before:

$result = $this->banco->getResult($sql);
return $result;

After:

$result = $this->banco->getResult($sql);
return $result[0]['TOTAL'];

Thank you!! :)