IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Ext JS / Sencha Discussion :

Extjs 4.2 : grid et sauvegarde des fitres à l'aide des stateful/stateId


Sujet :

Ext JS / Sencha

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 39
    Points : 39
    Points
    39
    Par défaut Extjs 4.2 : grid et sauvegarde des fitres à l'aide des stateful/stateId
    Bonjour,

    Alors voilà : j'ai une grosse question à vous poser ! ;-)
    J'ai mon datagrid avec des filtres,pagination,... et je souhaiterai que tout élément (filtres, pagination..) soit enregistrés dans le cookie Ext.state.CookieProvider et recharger en l'état quand je reviens sur cette grid : MAIS JE N ARRIVE PAS 0 FAIRE CELA !

    Est-ce que quelqu'un pourrait m'aider ??

    Merci d'avance.

    Mon code ci-dessous (rappel : tout fonctionne sauf la sauvegarde des états (state) pagination, filtres,...)
    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
     
    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'}
            ],
            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,
            proxy: {
                type: 'ajax',
                url: pref_url + 'index.php/JsonContrats',
                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_actif'}
            ]
        };
     
        var stCommerciaux = Ext.create('Ext.data.Store', {
            fields: ['id', 'text'],
            autoDestroy: true,
            proxy: {
                type: 'ajax',
                url: pref_url + 'index.php/jsoncommerciaux',
                reader: 'json'
            }
        });
     
        var grid = Ext.create('Ext.grid.Panel', {
            width: '98%',
            height: 700,
            title: 'Liste des contrats ingénius',
            store: store,
            disableSelection: false,
            loadMask: true,
            features: [filters],
            stateful: true,
            stateId: 'contratingenius' + monstateId,
            columns: {
                items: [{
                        id: 'CONT_NOCONTRAT',
                        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 target="_BLANK" href="' + pref_url + 'index.php/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: '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,
                stateful : true,
                stateId: 'contratingenius' + monstateId,
                displayInfo: true,
                displayMsg: 'Contrat(s) {0} - {1} de {2}',
                emptyMsg: "Aucun contrat à afficher"
            }),
            dockedItems: [Ext.create('Ext.Toolbar', {
                    dock: 'top',
                    store: store,
                    items: [/*{
                     xtype: 'button',
                     cls: 'button',
                     flex: 0,
                     text: ' ',
                     iconCls: 'add-user',
                     tooltip: 'Supprimer les filtres',
                     style: {
                     background: '#058C36'
                     },
                     handler: function () {
                     Ext.getCmp("filtre_contrat").reset();
                     //grid.filters.clearFilters();   
                     //grid.filters.reload();
                     var filter = grid.filters.getFilter('contrat_ingenius_filtres');
                     if (!filter) {
                     filter = grid.filters.addFilter({
                     active: true,
                     type: 'string',
                     dataIndex: 'contrat_ingenius_filtres'
                     });
                     }
                     
                     filter.setValue('contrat_ingenius_actif');
                     grid.filters.reload();                            
                     
                     }
                     },*/
                        {
                            xtype: 'button',
                            cls: 'button',
                            flex: 0,
                            text: 'Exporter au format Excel',
                            iconCls: 'add-user',
                            style: {
                                background: '#058C36'
                            },
                            tooltip: 'Exporter au format Excel',
                            handler: function (b, e) {
                                b.up('grid').downloadExcelXml();
                            }
                        }, {
                            xtype: 'radiogroup',
                            fieldLabel: 'Contrats',
                            columns: 4,
                            name: 'filtre_contrat',
                            id: 'filtre_contrat',
                            columns: [60, 90, 60, 90],
                                    items: [
                                        {boxLabel: 'Actifs', checked: true, name: 'filtre_contrat', inputValue: 'contrat_ingenius_actif'},
                                        {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) {
                                    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'
                                        });
                                    }
     
                                    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
            }
     
        });
    grid.restoreState();
    var state = Ext.state.Manager.getProvider();
        /*
        var state = Ext.state.Manager.getProvider();
        alert(state.get('start'));
        var start = (state.get('listingeniusgrid' + monstateId).start || 0);
        store.load({params: {start: 202, limit: itemsPerPage}});*/
    });

  2. #2
    Membre éclairé
    Avatar de abraxis
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2007
    Messages
    439
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2007
    Messages : 439
    Points : 658
    Points
    658
    Par défaut
    Bonjour,

    Si je ne me trompe pas il faut rajouter la propriété "stateFul: true" aux colonnes.
    # apt-get install freedom

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 39
    Points : 39
    Points
    39
    Par défaut
    Bonjour,

    Voici une représentation de ma ext-js grid :

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

    Vous voyez les boutons radio et la pagination en bas : le but est quand je suis sur cette page, que je fais une sélection de critère ou que j'avance dans la pagination => quand je quitte cette page et que je reviens après sur cette dernière, je souhaite retomber sur mes sélections faites précédemment.

    J'ai essayé plusieurs choses : mais ne fonctionne pas, je dois mal m'y prendre.

    Donc si vous avez des idées ou des morceaux de codes, je suis preneur.

    Merci de votre attention

    Cordialement,
    Christophe

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 39
    Points : 39
    Points
    39
    Par défaut
    Bonjour,

    J'avance un peu : j'arrive à garder mon state sur les checkbox, mais par contre quand je reviens sur ma page: j'ai le message d'erreur suivant "grid is undefined" sur 'listeners: {change':

    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
     
     {
                            xtype: 'radiogroup',
                            //--STATE
                            stateEvents: ['change'],
                            stateId:'radioingenius'+monstateId,
                            stateful:true,
                            getState: function() {
                                return { "checked": this.getValue() };
                            },
                            applyState: function(state) {
                                //this.callParent(state);
                                this.setValue( state.checked );
                            },
                            stateEvents: [
                                'click',
                                'change',
                                'check'
                            ],       
                            //--FIN STATE                        
                            //fieldLabel: 'Contrats',
                            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) {
                                    if(!grid){    
                                        console.log('KO apply filter '+store+grid);
                                    }else{
                                        console.log('apply filter '+grid);
                                        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(); 
                                    }
                                }
                            }
                        }
    Comment faire pour que ma variable grid soit reconnu lorsque je reviens sur ma page après initialisation du state de mon checkboxgroup ?

    Cordialement,
    Christophe

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 39
    Points : 39
    Points
    39
    Par défaut EXTJS 4.2.1 stateid : Help, j'suis au bord de la déprime là !
    Bonjour,
    Je me suis créer une datagrid :

    Nom : dt_grid.gif
Affichages : 392
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

Discussions similaires

  1. Réponses: 1
    Dernier message: 28/06/2012, 16h04
  2. Réponses: 1
    Dernier message: 27/04/2012, 16h41
  3. Réponses: 2
    Dernier message: 05/12/2011, 15h08
  4. creer des variables à l'aide des transformations
    Par Edna24 dans le forum Informatica
    Réponses: 0
    Dernier message: 19/06/2009, 16h16
  5. Deplacement des objets à l'aide des touches
    Par AmineDev9 dans le forum MFC
    Réponses: 4
    Dernier message: 07/05/2008, 16h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo