PDA

View Full Version : PagingGrid + JsonReader handling empty results



martinrame
15 Oct 2012, 2:42 PM
Hi, I'm using an Ext.grid.Panel with a verticalScrollerType: 'pagingridscroller" (aka Paging Grid) loaded from this JsonStore:


Ext.define('MyApp.store.Movimientos', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.Movimiento'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
pageSize: 100,
remoteSort: true,
remoteFilter: true,
buffered: true,
model: 'MyApp.model.Movimiento',
proxy: {
type: 'ajax',
api: {
read: '/cgi-bin/tarjeta.cgi/movimientos/read'
},
reader: {
type: 'json',
idProperty: 'IDMOVIMIENTO',
totalProperty: 'total',
successProperty: 'success',
root: 'root'
},
simpleSortMode: true
}, cfg)]);
}
});

When the query I made on the server side have results, the grid is working ok, I mean, it initially shows the loadMask, then the data. But, when the query returns empty results, the loadMask stays forever.

Here's an example of empty result:


{
"root" : [],
"success" : false,
"total" : 0
}

What I'm doing wrong?. I would like the loadMask to dissapear, then see the empty grid.

BTW: Using Extjs 4.1

vietits
15 Oct 2012, 3:40 PM
Try to return with success set to true instead of false.


{
"root" : [],
// "success" : false,
"success" : true,
"total" : 0
}

martinrame
15 Oct 2012, 3:55 PM
Thanks vietits!, that did the trick.

The answer raises a question, when should I use "success: false"?.

vietits
15 Oct 2012, 4:25 PM
You should return "success": false when for some reason you couldn't do the action normally, such as missing parameters. In that case, you should supply a callback function to <store>.load() (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-load) and then check the success argument to do the right thing.

martinrame
15 Oct 2012, 4:31 PM
Thanks great answer.