PDA

View Full Version : reader is loaded but store empty ?



Efex
27 Jun 2008, 9:02 AM
Hi,

What can be happening if my store is loaded but empty??
In firebug I see the reader has the response loaded ok.
Json is also fine as I've checked on JSLint.

Anyone?? :-?:-?:-?

devnull
27 Jun 2008, 9:05 AM
the json may pas jslint, but that doesnt mean it matches what the reader expects.
and you havent given us enough information to help with that.

Efex
27 Jun 2008, 10:10 AM
Thanks Devnull,

this is the code for my Store:



var reader = new Ext.data.JsonReader({}, [
{name: 'Articulo', type: 'string', mapping: 'label'},
{name: 'Descripcion', type: 'string', mapping: 'descripcion'},
{name: 'Categoria', type: 'string', mapping: 'categoria'},
{name: 'Subpartida', type: 'string', mapping: 'subpartida'},
{name: 'Unidad', type: 'string', mapping: 'unidad'},
{name: 'Cantidad', type: 'string', mapping: 'cantidad'},
{name: 'Ultima_mod', type:'date', mapping: 'ult_mod', dateFormat: 'Y-m-d H:i:s'}
]);

// create the data store
var resultStore = new Ext.data.GroupingStore({
url: 'index.php',
totalProperty: 'totalRecords',
root: 'resultadoGrid',
reader: reader,
sortInfo:{field: 'Articulo', direction: "ASC"},
remoteSort: true
});
The Json response I get is this:

({"totalRecords":4,"resultadoGrid":[{"cuenta_art":"1","recordID":"13","label":"Articulo 001","descripcion":"Articulo de pruebas","cod_categoria":"2","categoria":"MC-Mercadera","subpartida":"12.69.51.23.51","unidad":"500 PIEZAS(PZA),60 TONELADAS(TM),40000 PIES(FT)","cantidad":"500,60,40000","ult_mod":"2008-06-19 15:14:03"},{"cuenta_art":"1","recordID":"14","label":"Articulo 002","descripcion":"Aceites para elaboracion de resinas industriales","cod_categoria":"2","categoria":"MC-Mercadera","subpartida":"12.69.48.72.13","unidad":"150 BARRILES (42 GALON US)(BRR ),300000 LITRO (L ),8000000 ONZAS (OZ )","cantidad":"150,300000,8000000","ult_mod":"2008-06-19 15:14:03"},{"cuenta_art":"1","recordID":"15","label":"Aceite Crudo de Palma","descripcion":"","cod_categoria":"1","categoria":"MP-Materia prima","subpartida":"12.69.48.72.13","unidad":"2000 TONELADAS(TM),2000000 KILOGRAMO(KG)","cantidad":"2000,2000000","ult_mod":"2008-06-19 15:13:52"},{"cuenta_art":"1","recordID":"16","label":"Montacargas","descripcion":"Montacargas utilizado en el proceso de produccion","cod_categoria":"3","categoria":"MQ-Maquinaria","subpartida":"12.69.48.72.13","unidad":"1 UNIDADES(U)","cantidad":"1","ult_mod":"2008-06-19 14:51:43"}]})

Animal
27 Jun 2008, 10:26 AM
You are not configuring your JsonReader properly. It needs the totalProperty and root.

http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader

Efex
27 Jun 2008, 10:43 AM
ohhh, I see, so the totalProperty and root have to go on Reader but not in Store as I had?? :)

One thing though, I can see the store is loading twice :s
I make my store load on a listener from a combo and, on store 'load' listener, I make my grid render and the store loads again. :s:-?
Is this ok?

Thanks Animal as usual :)

27 Jun 2008, 10:45 AM
the reader doesn't 'load', it acts as a 'filter' to parse data and properly fill the 'slots' for the records that go into the data store.

Efex
27 Jun 2008, 11:13 AM
Yes, jgarcia.
Is the data store what I'm talking about.

Maybe with the code is better understood:



mycombo.on('select', function(us){
win_Choose_Cliente.hide();
resultStore.proxy= new Ext.data.HttpProxy({url: 'index.php?accion=consultarAdmSaldoInventarios&opcionExt=cargaGrid&dpCliente='+this.value});
resultStore.load({params: {start:0, limit: 2}});
});

//this loads my store correctlly :)

//now here's the listener for the loading of the store where I render my grid

resultStore.on({

'load':{
fn: function(store, records, options){
grid.render('menuActions');
grid.getSelectionModel().selectFirstRow();

//this is for checking on firebug
console.log('Data Store listener fired (load), arguments:',arguments);
console.log('Store count = ',store.getCount());

}
,scope:this

}
});

Efex
27 Jun 2008, 11:51 AM
Never mind :D:D

I solved the problem not loading the store but directlly rendering the grid on the combo select event :)

hendricd
27 Jun 2008, 12:06 PM
Are you sure about that? :-?

Do you really want to re-render the grid every time the combo selection changes?

27 Jun 2008, 12:07 PM
seems like a waste to me.

Efex
27 Jun 2008, 12:48 PM
yes hendricd :)

The combo is located on a modal window only shown when page is loaded for the first time to get a required param to build the grid