I get the right json format for the database records using Java .
Its like this.
Code:
{"device":[{"id":1,"uname":"Sachin","fname":"Sachin","lname":"Taware","emailid":"sachi@gmail.com","statename":"MH","cityname":"Pune","countryname":"India"},{"id":2,"uname":"Rahul","fname":"Rahul","lname":"Dravid","emailid":"rdravid@gmail.com","statename":"KA","cityname":"Bangalore","countryname":"India"},{"id":3,"uname":"MS","fname":"MS","lname":"Dhoni","emailid":"ms@gmail.com","statename":"JH","cityname":"Ranchi","countryname":"India"},{"id":4,"uname":"viru","fname":"Virender","lname":"Sehwag","emailid":"viru123@gmail.com","statename":"DL","cityname":"Delhi","countryname":"India"}]
I have my script in an Html file.
But,now how can I pass it to the store?
The problem I think is in the proxy and reader section(I have highlighted it).Can I pass the URL of the class file of the compiled servlet ??If not how to pass the json to the store?
Firebug shows me the same error of invalid json.I went though the PHP examples and there we give the .php
file as URL.
Code:
<script type="text/javascript">
Ext.onReady(function() {
Ext.define('Company', {
extend: 'Ext.data.Model',
fields: [
{name:'uname',type: 'string'},
{name:'fname',type: 'string'},
{name:'lname',type: 'string'},
{name:'emailid',type: 'string'},
{name:'statename',type: 'string'},
{name:'cityname',type: 'string'},
{name:'country',type: 'string'}]
});
var store_company = new Ext.data.Store({
model: 'Company',
proxy: {
type: 'ajax',
url: 'register.class',
reader: {
type: 'json',
root:'device'
},
}
});
var grid_company = Ext.create('Ext.grid.Panel', {
store: store_company,
columns:[
{
text : 'User Name',
width : 120,
sortable : true,
dataIndex: 'uname'
},
{
text : 'Firstname',
width : 120,
sortable : true,
dataIndex: 'fname'
},
{
text : 'Lastname',
width : 110,
sortable : true,
dataIndex: 'lname'
},
{
text : 'Email',
width : 150,
sortable : true,
dataIndex: 'emailid'
},
{
text : 'State',
width : 100,
sortable : true,
dataIndex: 'statename'
},
{
text : 'City',
width : 150,
sortable : true,
dataIndex: 'cityname'
},
{
text : 'Country',
width : 150,
sortable : true,
dataIndex: 'countryname'
}
],
bbar: Ext.create('Ext.PagingToolbar', {
store: store_company,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
}),
height: 210,
width: 902,
title: 'Company List',
renderTo: 'grid-company',
viewConfig: {
stripeRows: true
}
});
store_company.load();
});
</script>
Regards
Sachin