1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    9
    Vote Rating
    0
    Answers
    1
    tamri is an unknown quantity at this point

      1  

    Default Unanswered: extjs4 STORE into CheckboxGroup

    Unanswered: extjs4 STORE into CheckboxGroup


    I create store, load records and want to fill CheckboxGroup with it. but I can't show CheckboxGroup in the form.
    records is loaded, but checkboxes not displayed.
    there is my code. i spend hole day, read all recommendations ...
    what is wrong ??
    anyone help !
    Code:
       var checkboxes = [];
    var resourceVacancesStore = Ext.create('Ext.data.Store', {
           model:operationTypeModel,
           proxy: 
            {   
               type: 'ajax'    ,              
               url:'url',
               idProperty: 'oId',
               autoLoad:true,        
                 reader: {
                     type: 'json',   
                   root: 'data'} 
            }    ,
            listeners: {                                                                                                                         
            load: function(t, records, options) {   
            var checkboxconfigs=[];
                for(var i = 0; i < records.length; i++) {                    
                    checkboxconfigs.push({
                         name: records[i].data.oId,
                         inputValue: records[i].data.oNameEn,
                         boxLabel : records[i].data.oNameEn,
                         xtype: 'checkbox'
                     });                  
                     processItems(checkboxconfigs);                 
                }
            }                                                                                                                                  
        }  
       });
    
       function processItems(items){
         checkboxes =items;
        }
    
       var myCheckboxgroup = new Ext.form.CheckboxGroup({
            id:'myGroup',
            fieldLabel: 'Checkboxes in two columns',
            items:checkboxes ,
            renderData :main
        });
       resourceVacancesStore.load();

  2. #2
    Sencha User lucasguaru's Avatar
    Join Date
    May 2011
    Location
    Guaruj√°, Brazil
    Posts
    77
    Vote Rating
    2
    Answers
    9
    lucasguaru is on a distinguished road

      0  

    Default


    You can try to create the checkboxgroup when the store loads.
    Code:
    var resourceVacancesStore = Ext.create('Ext.data.Store', {
        model : operationTypeModel,
        proxy : {
            type : 'ajax',
            url : 'url',
            idProperty : 'oId',
            autoLoad : true,
            reader : {
                type : 'json',
                root : 'data'
            }
        },
        listeners : {
            load : function(t, records, options) {
                var checkboxconfigs = [];
                for ( var i = 0; i < records.length; i++) {
                    checkboxconfigs.push({
                        name : records[i].data.oId,
                        inputValue : records[i].data.oNameEn,
                        boxLabel : records[i].data.oNameEn,
                        xtype : 'checkbox'
                    });
                }
                var myCheckboxgroup = new Ext.form.CheckboxGroup({
                    id : 'myGroup',
                    fieldLabel : 'Checkboxes in two columns',
                    items : checkboxconfigs,
                    renderData : main
                });
            }
        }
    });
    The problem is if you loads the store many times.

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    Answers
    545
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Something like this perhaps?

    Code:
    var myCheckboxGroup = Ext.create('Ext.form.CheckboxGroup', {
        fieldLabel: 'Checkboxes in two columns',
        renderTo: Ext.getBody()
    });
    
    var resourceVacancesStore = Ext.create('Ext.data.Store', {
        autoLoad: true,
        model: operationTypeModel,
        listeners: {
            load: function(store, records) {
                myCheckboxGroup.removeAll();
    
                myCheckboxGroup.add(Ext.Array.map(records, function(record) {
                    return {
                        boxLabel: record.get('oNameEn'),
                        inputValue: record.get('oNameEn'),
                        name: record.get('old')
                    };
                }));
            }
        },
        proxy: {
            type: 'ajax',
            url: 'url',
            reader: {
                root: 'data',
                type: 'json'
            }
        }
    });

  4. #4
    Sencha User
    Join Date
    Aug 2011
    Posts
    9
    Vote Rating
    0
    Answers
    1
    tamri is an unknown quantity at this point

      0  

    Default


    it does not work, maybe there are other problems.

    myCheckboxGroup not shows records

  5. #5
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,616
    Vote Rating
    327
    Answers
    545
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Shove in some breakpoints, check if the code's running and what happens when it does.

  6. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    9
    Vote Rating
    0
    Answers
    1
    tamri is an unknown quantity at this point

      -1  

    Default


    now it works!
    solution :
    it didn't work until i don't have written layout on checkboxgroup (layout is not required config in the documentation).

    thank's!

Thread Participants: 2