PDA

View Full Version : Loading Store into Form Panel textfield's values dynamically from database



lokendarreddy
26 Sep 2012, 10:57 PM
Am using Form Panel to create a form by using ExtJS 4.1 . And i wanto load the form with values getting from database. So i am getting JsonStore from database with required values like name, email, mobile no etc. So i am getting problem at how to read the values from store and model and how to render those values into textfields values.


Please can you provide some hints in rendering data into Form Panel text fields from Store.

sword-it
26 Sep 2012, 11:51 PM
Hi lokendar,

Try with this code-


Ext.create('Ext.FormPanel', {
width: 500,
title: 'Parent Panel',
afterRender: function() {
this.superclass.afterRender.apply(this);
this.mask('Please Wait');
Ext.Ajax.request({
url: '/echo/json/', //Give your url here
scope: this,
success: function(data) {
this.unmask();
FormRecord= Ext.JSON.decode(data.responseText) // decode your responseText from JSON to object
this.getForm().setValues(FormRecord); // get your formPanel and set form field value
},
failure: function() {
alert('Load Fail')
}
});
},
items: [{
xtype: 'textfield',
fieldLabel: 'Name'},
{
xtype: 'combo',
fieldLabel: 'Age',
store: ['15', '25', '35']
}],
renderTo: Ext.getBody(),
});

lokendarreddy
27 Sep 2012, 2:11 AM
Thanks for giving reply..........

I have tried with given example but i am getting data in below format.

data format is : {"data":[{"Name":"project1"}]}

This data format is receiving from my servlet. But is is not rendering the values in text field. So please suggest me in which format i have to provide response for ajax request.