PDA

View Full Version : extjs4 STORE into CheckboxGroup



tamri
13 Oct 2011, 2:23 AM
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 !


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();

lucasguaru
13 Oct 2011, 3:45 AM
You can try to create the checkboxgroup when the store loads.


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.

skirtle
13 Oct 2011, 4:09 AM
Something like this perhaps?


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'
}
}
});

tamri
16 Oct 2011, 10:57 PM
it does not work, maybe there are other problems.

myCheckboxGroup not shows records

skirtle
17 Oct 2011, 3:14 AM
Shove in some breakpoints, check if the code's running and what happens when it does.

tamri
19 Oct 2011, 10:59 PM
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!