Hello tout le monde,

J'ai installé extJS hier. Avec l'installation de base, je me suis fait un GridWindow.

Dans son paramètre items, il y a store qui est de type new Ext.data.ArrayStore
Le store contient les data de la grid (punaise, ça devient du franglais).
Les data sont chargées de cette façon : data: MyDesktop.GridWindow.getBots()

et la fonction est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
        getBots: function () {
			$.ajax({
				url : 'includes/botsStatus.php',
				dataType: "json",
				beforeSend: function(x) {
					if(x && x.overrideMimeType) {
						x.overrideMimeType("application/json;charset=UTF-8");
					}
				},
				success :
				function(data) {
					return data;
				},
				error :
				function (data) {
					alert('erreur ' + data);
				}
			});
        }
Le fichier PHP est super simple, j'ai tenté avec quelque chose de basique :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
<?php 
$data = "[
        ['testuser','testpwd','0'],
        ['user2','pwd2','1']
]";
echo json_encode($data);
?>
L'erreur n'est pas levée. Donc la requête est correcte. Si je fais un alerte, ça passe aussi. Or le store ne trouve aucun élément :
Uncaught TypeError: Cannot read property 'length' of undefined - Store.js:2278
Normalement, ça devrait être un object ( http://docs.sencha.com/ext-js/4-1/#!...ata.ArrayStore ). Si je fais un simple
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
return [
	['testuser','testpwd','0'],
	['user2','pwd2','1']
];
au lieu de faire l'appel en ajax dans la fonction, ça passe nickel, mais du coup ce n'est plus dynamique.
Savez-vous d'où provient mon problème ?

Merci

PS : Le fichier GridView.js en entier est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*!
 * Ext JS Library 4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
 
Ext.define('MyDesktop.GridWindow', {
    extend: 'Ext.ux.desktop.Module',
 
    requires: [
        'Ext.data.ArrayStore',
        'Ext.util.Format',
        'Ext.grid.Panel',
        'Ext.grid.RowNumberer'
    ],
 
    id:'grid-win',
 
    init : function(){
        this.launcher = {
            text: 'Bots Status',
            iconCls:'icon-grid'
        };
    },
 
    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Bots Status',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                animCollapse:false,
                constrainHeader:true,
                layout: 'fit',
                items: [
                    {
                        border: false,
                        xtype: 'grid',
						selModel: Ext.create('Ext.selection.CheckboxModel'),
                        store: new Ext.data.ArrayStore({
                            fields: [
                               { name: 'username' },
                               { name: 'password' },
                               { name: 'status', type: 'float' }
                            ],
                            data: MyDesktop.GridWindow.getBots()
                        }),
                        columns: [
                            new Ext.grid.RowNumberer(),
                            {
                                text: "Username",
                                flex: 1,
                                sortable: true,
                                dataIndex: 'username'
                            },
                            {
                                text: "Password",
                                width: 70,
                                dataIndex: 'password'
                            },
                            {
                                text: "Status",
                                width: 70,
                                sortable: true,
                                dataIndex: 'status'
                            }
                        ]
                    }
                ],
                tbar:[{
                    text:'Add',
                    tooltip:'Add a new bot',
                    iconCls:'add'
                }, '-', {
                    text:'Check',
                    tooltip:'Modify options',
                    iconCls:'option',
					handler: function() {
						alert('ok');
					}
                },'-',{
                    text:'Remove',
                    tooltip:'Remove the selected bots',
                    iconCls:'remove'
                }]
            });
        }
        return win;
    },
 
    statics: {
        getBots: function () {
			$.ajax({
				url : 'includes/botsStatus.php',
				dataType: "json",
				beforeSend: function(x) {
					if(x && x.overrideMimeType) {
						x.overrideMimeType("application/json;charset=UTF-8");
					}
				},
				success :
				function(data) {
					return data;
				},
				error :
				function (data) {
					alert('erreur ' + data);
				}
			});
        }
    }
});