Bonjour,
Je me suis créer une datagrid :

Nom : dt_grid.gif
Affichages : 299
Taille : 23,9 Ko

Je suis en train d'essayer de gérer le sateful sur les filtres (Tous,Actifs,Inactifs,Suspendus,Tests,Résiliés) de mon dockpanel : j'y arrive presque, mais je rencontre un dernier soucis.
Voici un moreau de mon code :

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
 
, {
                        xtype: 'radiogroup',
                        id:'radiogroup',
                        itemId: 'radiogroup',     
                        name:'radiogroup',
                        //--STATE
                        stateEvents: ['change'],
                        stateId:'radioingenius'+monstateId,
                        stateful:true,
                        getState: function() {
                            return { "checked": this.getValue()};
                        },
                        applyState: function(state) {   
                            this.setValue( state.checked );
                        },   
                        //--FIN STATE                        
                        columns: 6,
                        name: 'filtre_contrat',
                        id: 'filtre_contrat',
                        columns: [60,60,63, 90, 60, 90],
                                items: [
                                    {boxLabel: 'Tous', checked: true, name: 'filtre_contrat', inputValue: 'contrat_ingenius_all'},
                                    {boxLabel: 'Actifs', name: 'filtre_contrat', inputValue: 'contrat_ingenius_actif'},
                                    {boxLabel: 'Inactifs', name: 'filtre_contrat', inputValue: 'contrat_ingenius_inactif'},
                                    {boxLabel: 'Suspendus', name: 'filtre_contrat', inputValue: 'contrat_ingenius_suspendus'},
                                    {boxLabel: 'Tests', name: 'filtre_contrat', inputValue: 'contrat_ingenius_tests'},
                                    {boxLabel: 'Résiliés', name: 'filtre_contrat', inputValue: 'contrat_ingenius_resilies'}
                                ],
                        listeners: {
 
                            change: function (field, newValue, oldValue,eOpts) {
                                if(!grid){    
                                    //grid = this.grid;// Ext.get('#myGrid'); //Ext.ComponentQuery.query('gridpanel[name="myGrid"]');// Ext.ComponentQuery.query('#myGrid');  ==> fonctionnent pas !
                                    grid = this.up('myGrid');
                                    console.log('dd =>'+grid);
                                    //filters.reload();
                                    //grid = Ext.ComponentQuery.query('gridpanel[id=myGrid]');  ==> fonctionnent pas !
                                    //grid = Ext.getCmp("myGrid"); //field.up('gridpanel'); //field.up('gridpanel #myGrid');//field.up('radiogroup');//Ext.getCmp("grid");//field.up('grid'); ==> fonctionnent pas !
                                    // QUE FAIRE POUR RETROUVER MON OBJET  GRID APRES RETOUR SUR CETTE PAGE ?
 
 
 
                                }else{
                                    console.log('apply filter '+grid+newValue);
                                    var value = newValue.filtre_contrat;
                                    var filter = grid.filters.getFilter('contrat_ingenius_filtres');
                                    if (!filter) {
                                        filter = grid.filters.addFilter({
                                            active: true,
                                            type: 'string',
                                            dataIndex: 'contrat_ingenius_filtres'
                                        });
                                    }
                                    //this.value =  newValue;
                                    filter.setValue(value);
                                    grid.filters.reload(); 
                                }
                            }
                        }
                    }
Mon problème est le suivant :
- lorsque j'arrive la première fois sur ma page, dans le listener "change" : ma variable grid est bien reconnu
- par contre, je quitte ma page ou il y a le datagrid et j'y retourne ensuite : filtre_contrat contient bien la dernière valeur selectionner mais par contre ma variable grid n'est plus reconnu et je n'arrive pas à accéder à mon grid

Donc, j'espère que vous m'aurez compris et si vous pouvez me donner un coup de main ce serait génial.

Merci de votre attention et si vous avez des questions n'hésitez pas à me contacter.

Si vous voulez voire mon code complet :
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
 
Ext.Loader.setConfig({enabled: true});
 
Ext.require([
    'Ext.grid.*',
    'Ext.state.*',
    'Ext.data.*',
    'Ext.toolbar.Paging',
    'Ext.ux.grid.FiltersFeature',
    'Ext.ux.ajax.JsonSimlet',
    'Ext.ux.ajax.SimManager',
    'Ext.ux.exporter.*',
    //'Ext.ux.grid.FilterBar',
    'Ext.ux.form.field.ClearButton',
    'Ext.ux.form.field.OperatorButton',
    'Ext.ux.grid.column.ActionPro',
    'Ext.ux.grid.AutoResizer'
]);
 
var itemsPerPage = 53;
 
 
 
Ext.onReady(function () {
    Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
    Ext.tip.QuickTipManager.init();
 
    Ext.define('ContratModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'CONT_NOCONTRAT'},
            {name: 'client_nom'},
            {name: 'client_prenom'},
            {name: 'type_pro'},
            {name: 'TEL_DATE_1', type: 'date'},
            {name: 'TERM_APPL_VERDATE'},
            {name: 'TERM_CODEP'},
            {name: 'client_nom_commercial'},
            {name: 'dst_societe'},
            {name: 'conncetis'},
            {name: 'CONT_FLAG_RESIL'},
            {name: 'test'},
            {name: 'date_suspension'},
            {name: 'client_cp'},
            {name: 'groupe_sos_id'},
            {name: 'sos_medecin'}
        ],
        idProperty: 'CONT_NOCONTRAT'
    });
 
 
    var store = Ext.create('Ext.data.JsonStore', {
        autoDestroy: true,
        pageSize: itemsPerPage, // items per page
        model: 'ContratModel',
        remoteSort: true,
        stateful: true,
        stateId: 'contratingenius' + monstateId,
        stateEvents : [ 'change' ],
        proxy: {
            type: 'ajax',
            url: pref_url + 'index.php/ingenius/contrat/JsonContratIngenius',
            reader: {
                root: 'contrats',
                totalProperty: 'totalCount'
            },
            simpleSortMode: true
        },
        sorters: [{
                property: 'CONT_NOCONTRAT',
                direction: 'DESC'
            }]
    });
 
    var filters = {
        ftype: 'filters',
        encode: true,
        local: false,
        id: 'approvedFilter',
        stateful: true,
        stateId: 'contratingenius' + monstateId,
        filters: [
            {type: 'string', dataIndex: 'contrat_ingenius_filtres', value: 'contrat_ingenius_all'}
        ]
    };
 
    var stCommerciaux = Ext.create('Ext.data.Store', {
        fields: ['id', 'text'],
        autoDestroy: true,
        proxy: {
            type: 'ajax',
            url: pref_url + 'index.php/client/default/jsoncommerciaux',
            reader: 'json'
        }
    });
 
 
 
    grid = Ext.create('Ext.grid.Panel', {
        singleton: true,
        xtype: 'grid',
        itemId: 'myGrid',        
        id: 'myGrid',  
        name: 'myGrid',  
        width: '98%',
        height: 700,
        //title: 'Liste des contrats ingénius',
        store: store,
        disableSelection: false,
        loadMask: true,
        features: [filters],
        stateful: true,
        stateId: 'contratingenius' + monstateId,
        stateEvents: ['columnmove', 'columnresize', 'groupchange', 'bodyresize', 'sortchange', 'selectionchange', 'filterchange'],  
        columns: {
            items: [{
                    id: 'CONT_NOCONTRAT',
                    stateId: 'INGENIUS_CONT_NOCONTRAT_COL',
                    text: "Contrat",
                    dataIndex: 'CONT_NOCONTRAT',
                    width: 80,
                    hidden: false,
                    sortable: true,
                    filter: {type: 'int'},
                    filterable: true,
                    tdCls: 'x-change-cell',
                    renderer: function (val, meta, record) {
                        return '<a href="' + pref_url + 'index.php/ingenius/contrat/edit?num_contrat=' + val + '">' + val + '</a>';
                    }
                }, {
                    flex: true,
                    id: 'client_nom',
                    text: "Nom",
                    dataIndex: 'client_nom',
                    width: 195,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'client_prenom',
                    text: "Prénom",
                    dataIndex: 'client_prenom',
                    width: 195,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'client_cp',
                    text: "Code Postal",
                    dataIndex: 'client_cp',
                    width: 170,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'type_pro',
                    text: "Type de PS",
                    dataIndex: 'type_pro',
                    width: 105,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'TEL_DATE_1',
                    text: "Dernière télécollecte",
                    dataIndex: 'TEL_DATE_1',
                    width: 105,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    filter: {type: 'date'},
                    tdCls: 'x-change-cell',
                    renderer: function (val, meta, record) {
                        return  Ext.util.Format.date(val, 'd/m/Y');
                    }
                }, {
                    flex: false,
                    id: 'TERM_APPL_VERDATE',
                    text: "Version Appli.",
                    dataIndex: 'TERM_APPL_VERDATE',
                    width: 110,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'TERM_CODEP',
                    text: "Code produit",
                    dataIndex: 'TERM_CODEP',
                    width: 195,
                    align: 'left',
                    sortable: true,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'client_nom_commercial',
                    text: "Commercial",
                    dataIndex: 'client_nom_commercial',
                    width: 130,
                    sortable: true,
                    hidden: false,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {
                        type: 'list',
                        options: [],
                        phpMode: true,
                        store: stCommerciaux
                    }
                }, {
                    flex: true,
                    id: 'dst_societe',
                    text: "Distributeur",
                    dataIndex: 'dst_societe',
                    width: 130,
                    sortable: true,
                    hidden: false,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }, {
                    flex: true,
                    id: 'connectis',
                    text: "Connectis",
                    dataIndex: 'connectis',
                    width: 130,
                    sortable: true,
                    hidden: false,
                    filterable: true,
                    tdCls: 'x-change-cell',
                    filter: {type: 'string'}
                }
            ]
        },
        bbar: Ext.create('Ext.PagingToolbar', {
            store: store,
            stateEvents : [ 'change' ],     
            stateful : true,
            stateId: 'contratingeniuspaging' + monstateId,
            /*getState: function(){
                console.log('change paging ');
                return this.store.pageSize;
                //return this.store;
            },
            applyState: function(state) {
                if (state) {
                    console.log('apply state paging '+state);
                    Ext.apply(this, state);
                }
            },    */      
            style: {
                //background: '#97A563'
                background: 'green',
                color: 'white'
            },            
            displayInfo: true,   
            displayMsg: 'Contrat(s) {0} - {1} de {2}',
            emptyMsg: "Aucun contrat à afficher"
        }),
        dockedItems: [Ext.create('Ext.Toolbar', {
                dock: 'top',
                id:'myToolbar',
                itemId: 'myToolbar',   
                store: store,
                        style: {
                            background: 'green',
                            color: 'white',
                            font:'bold'
                        },
                items: [
                    {
                        xtype: 'button',
                        cls: '.btn-excel',
                        flex: 0,
                        text: 'Exporter au format Excel',
                        iconCls: 'add-user',
                        tooltip: 'Exporter au format Excel',
                        handler: function (b, e) {
                            b.up('grid').downloadExcelXml();
                        }
                    }, {
                        xtype: 'radiogroup',
                        id:'radiogroup',
                        itemId: 'radiogroup',     
                        name:'radiogroup',
                        //--STATE
                        stateEvents: ['change'],
                        stateId:'radioingenius'+monstateId,
                        stateful:true,
                        getState: function() {
                            return { "checked": this.getValue()};
                        },
                        applyState: function(state) {   
                            this.setValue( state.checked );
                        },   
                        //--FIN STATE                        
                        columns: 6,
                        name: 'filtre_contrat',
                        id: 'filtre_contrat',
                        columns: [60,60,63, 90, 60, 90],
                                items: [
                                    {boxLabel: 'Tous', checked: true, name: 'filtre_contrat', inputValue: 'contrat_ingenius_all'},
                                    {boxLabel: 'Actifs', name: 'filtre_contrat', inputValue: 'contrat_ingenius_actif'},
                                    {boxLabel: 'Inactifs', name: 'filtre_contrat', inputValue: 'contrat_ingenius_inactif'},
                                    {boxLabel: 'Suspendus', name: 'filtre_contrat', inputValue: 'contrat_ingenius_suspendus'},
                                    {boxLabel: 'Tests', name: 'filtre_contrat', inputValue: 'contrat_ingenius_tests'},
                                    {boxLabel: 'Résiliés', name: 'filtre_contrat', inputValue: 'contrat_ingenius_resilies'}
                                ],
                        listeners: {
 
                            change: function (field, newValue, oldValue,eOpts) {
                                if(!grid){   
									// aprés avoir quitté cette page et y être revenu : mon objet grid n'existe plus
                                    //grid = this.grid;// Ext.get('#myGrid'); //Ext.ComponentQuery.query('gridpanel[name="myGrid"]');// Ext.ComponentQuery.query('#myGrid');
                                    grid = this.up('myGrid');
                                    console.log('dd =>'+grid);
                                    //filters.reload();
                                    //grid = Ext.ComponentQuery.query('gridpanel[id=myGrid]');
                                    //grid = Ext.getCmp("myGrid"); //field.up('gridpanel'); //field.up('gridpanel #myGrid');//field.up('radiogroup');//Ext.getCmp("grid");//field.up('grid');
                                    //console.log('KO apply filter '+grid);
                                }else{
                                    console.log('apply filter '+grid+newValue);
                                    var value = newValue.filtre_contrat;
                                    var filter = grid.filters.getFilter('contrat_ingenius_filtres');
                                    if (!filter) {
                                        filter = grid.filters.addFilter({
                                            active: true,
                                            type: 'string',
                                            dataIndex: 'contrat_ingenius_filtres'
                                        });
                                    }
                                    //this.value =  newValue;
                                    filter.setValue(value);
                                    grid.filters.reload(); 
                                }
                            }
                        }
                    }
                ]
            })],
        renderTo: 'contrat-ingenius-grid',
        selModel: {
            selType: 'cellmodel'
        },
        viewConfig: {
            stripeRows: true,
            getRowClass: function (record, index) {
                var c = record.get('CONT_FLAG_RESIL');
                if (c == true) {
                    return 'ingenius-resilie';
                } else {
                    var suspendu = record.get('date_suspension');
                    if (suspendu != "00/00/0000")
                        return 'ingenius-suspendu';
                    var test = record.get('test');
                    if (test == true) {
                        return 'ingenius-test';
                    }
                }
            }
        },
        frame: false
    });
 
 
    store.load({
        params: {
            start: 0,
            limit: itemsPerPage
        }
 
    });
});
Cordialement,
Christophe