PDA

View Full Version : [Solved] Combo - Grid - Jsonstore - Error loading



senacle
9 Mar 2010, 1:49 PM
Hello,

I've a form with a datefield and a combo.
When i choose a date, the combo is populated from data coming from database.
It's working fine.

Then, i choose a data in the combo and there's a listview that must be populated with data coming from json.

The json datas are good.

But when loading json into the listview, i've the following issue in firebug : "g is undefined in ext-all.js (ligne 7)".

I've searched and tried some code, but always the same message.

Here is my code :



var donnee_course = new Ext.data.JsonStore({
root: 'rapport_course',
fields:[
'nom_rapport',
'combinaison_rapport',
'valeur_rapport'
]
});

var tableau=new Ext.ListView({
id: 'idjs_verif_course_tableau',
store: donnee_course,
autoHeight: true,
autoWidth: true,
disableHeaders: true,
loadingText: 'Chargement en cours...',
columns: [
{
header: 'Rapport',
dataIndex: 'nom_rapport',
align: 'center'
},{
header: 'Combinaison',
dataIndex: 'combinaison_rapport',
align: 'center'
},{
header: 'Valeur',
dataIndex: 'valeur_rapport',
align: 'center'
}]
});

var verif_course_panel = new Ext.Panel({
id: 'idjs_verif_course_panel',
title: 'Rapports de la course',
autoHeight: true,
items: [
new Ext.Panel({
id: 'lien',
html: 'coucoucoucoucoocuocuoucouco ',
autoHeight: true
}),
tableau
]
});


var verif_course_form = new Ext.FormPanel ({
id: 'idjs_verif_course',
labelWidth: 100,
frame:true,
bodyStyle:'padding:5px 5px 0',
width: 300,
items: [{
fieldLabel: 'Date ',
name: 'date_course',
id: 'date_course',
xtype: 'datefield',
allowBlank:false,
listeners: {
select:
function() {
var date = Ext.getCmp('date_course').getValue();
var combo = Ext.getCmp('idjs_numero_course');
combo.store.reload({params: {date_course: date}});
}
}
},
new Ext.form.ComboBox({
width: 150,
allowBlank: false,
fields: ['id_course', 'numero_course'],
displayField:'numero_course',
valueField:'id_course',
hiddenName:'id_course',
emptyText:'Sélectionner une course...',
fieldLabel: 'Course ',
id: 'idjs_numero_course',
name: 'id_course',
selectOnFocus:true,
store: course,
triggerAction: 'all',
typeAhead: true,
lastQuery: '',
listeners: {
select:
function() {
var date = Ext.getCmp('date_course').getValue();
var numero_course = Ext.getCmp('idjs_numero_course').getValue();
Ext.getCmp('idjs_verif_course').getForm().submit({
url: 'rapport_course.php',
method: 'POST',
reset: false,//pour ne pas reseter le formulaire en cas d'échec
failure: function(result, action) {
obj = Ext.decode(action.response.responseText);
var message = obj.errors;
},
success: function(result, action) {
Ext.getCmp('lien').update('comment ça va ?');
obj = Ext.util.JSON.decode(action.response.responseText);
var donnee = obj.rapport_course;
var id_verif_course_panel = Ext.getCmp('idjs_verif_course_panel');
var id_verif_course_tableau = Ext.getCmp('idjs_verif_course_tableau');
id_verif_course_panel.setTitle ('Rapports pour la course ' + Ext.getCmp('idjs_numero_course').getRawValue() + ' du ' + date.format('d/m/Y') + donnee[0]['combinaison_rapport']);
id_verif_course_panel.render('idjs_tab_verif_course');
donnee_course.loadData(donnee); <---here is the issue
}
});
}
}
})
]
});

senacle
10 Mar 2010, 12:02 AM
Well, i put ext-all-debug.js in the top of my web page and i found this message :

root is undefined

So, i changed to :



var donnee_course = new Ext.data.JsonStore({
fields:[
'nom_rapport',
'combinaison_rapport',
'valeur_rapport'
]
});


And now, the listview is populated :)

Why ?

The json is :



{success:true, rapport_course:[{"combinaison_rapport":"5","valeur_rapport":"6.8","nom_rapport":"Simple gagnant"},...

The root is rapport_course, isn't it ?

Zdeno
10 Mar 2010, 3:26 AM
Aye the root is 'rapport_course'. I think better param instead of success would be 'totalCount', isnt it? It define number of rows you have in response.

Watch the example on
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.JsonStore
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader

root : String
[undefined] Required. The name of the property which contains the Array of row objects. Defaults to undefined. An exception will be thrown if the root property is undefined. The data packet value for this property should be an empty array to clear the data or show no data.