PDA

View Full Version : read the data from database and display checkbox group in form



barbara1712
8 Oct 2012, 8:25 PM
Hi ,
I want to read the data from database and display the values in chekbox group and then display the form.
I have created a store. on load listener, I read the data and store the data in an array. and this array I want to set as items for my checkboxgroup. Please check the below code


var arrRatings = [];
var arrReader = new Ext.data.JsonReader({
root: 'data',
totalProperty:'totalCount'
}, [
{name: 'id', mapping:'id'},
{name: 'ratings', mapping:'ratings'}
]
)

arrRatStore = new Ext.data.Store({
url:'./CentralController.php?menu_no_top=perf_review&reviewcode=INITAPPR&action=loadRatingsData',
reader:arrReader,
autoLoad:true,
listeners:{
load:function(a,records,options){
for(i=0; i < records.length; i++){
arrRatings.push(
{
boxLabel:records[i].data.ratings,
name:'chkRatings[]',
inputValue: records[i].data.id,
checked:'false'
}
)
}
}
}
});

myform= new Ext.FormPanel({
id:'myform',
name:'myform',
buttonAlign:'right',
url:'myurl',
border:false,
title:'My Form',
layout:'table',
width:600,
items:[
{
xtype: 'checkboxgroup',
name: 'chkRatings',
id:'chkRatings',
fieldLabel: ' Define Ratings:',
columns:3,
items:arrRatings
}
]
});

//arrRatStore.load();
myform.render(document.body);
//arrRatStore.load();


Please help me.
Thanks in advance.

mitchellsimoens
15 Oct 2012, 2:13 PM
What is your JSON response looking like?

barbara1712
16 Oct 2012, 10:32 PM
Hi Thanks for reply. This is my json


{"success":true,"totalCount":6,"data":[{"id":"1","ratings":"Outstanding"},{"id":"2","ratings":"Excellent"},{"id":"3","ratings":"Exceeds Expectations"},{"id":"4","ratings":"Meets Expectations"},{"id":"5","ratings":"Falls short of Expectations"},{"id":"6","ratings":"Needs Improvement"}]}