I am trying to read a JSON response into Ext.grid.Panel using Ajax . However, Grid is showing only last record out of 5 results, can anyone please help:
JSON Response:
{"tweets":[{"text":"T 1156 -On #KBC the 1 crore winner Taj Mohammed Rangrez ... requires great maturity and guts to leave #KBC at 1crore and 2 lifelines unused","date":"1379273177","user":"\/SrBachchan","id":"145125358"},{"text":"T 1156 -Taj Mhammed Rangrez wins 1 crore rupees at #KBC .. what a game he played .. and he, such a beautiful human !! write in to #KBC","date":"1379272401","user":"\/SrBachchan","id":"145125358"},{"text":"T 1156 -SO ... what did you think of the 1st Crorepati winner on #KBC ... send in your comments to me through the #KBC tag .. love ya !!","date":"1379272302","user":"\/SrBachchan","id":"145125358"},{"text":"T 1156 -The last 2 tweets should have been numbered T 1156 ... apologies !!","date":"1379272226","user":"\/SrBachchan","id":"145125358"},{"text":"T 1155 -Ashok Chakradhar writes : \u092a\u094d\u0930\u0936\u094d\u0928 2. \u0905\u0928\u093e\u0921\u093c\u0940 \u091c\u0940, \u0906\u091c\u0915\u0932 \u0926\u0942\u0938\u0930\u094b\u0902 \u0915\u093e \u092d\u0932\u093e \u0915\u0930\u0928\u0947 \u0935\u093e\u0932\u094b\u0902 \u0915\u094b \u092c\u0947\u0935\u0915\u0942\u092b \u0938\u092e\u091d\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0964 (cont) http:\/\/tl.gd\/n_1rmfn3e ","date":"1379270895","user":"\/SrBachchan","id":"145125358"}]}
Ext Code:
var tweetModel = Ext.define('Tweet', {
extend: 'Ext.data.Model',
fields: [
{ name: 'text', type: 'string' },
{ name: 'date', type: 'string' },
{ name: 'user', type: 'string' },
{ name: 'id', type: 'string' }
]
});
var v= Ext.create('Ext.data.Store', {
model: tweetModel,
proxy: {
type: 'ajax',
url: '',
reader: {
type: 'json',
root: 'tweets'
}
}
});
var trailerPanel= Ext.create('Ext.grid.Panel', {
title: 'Tweets List',
store: v,
columns: [
{text: 'Text', dataIndex:'text',filterable: true},
{text: 'Date', dataIndex:'date',filterable: true},
{text: 'User', dataIndex:'user',filterable: true},
{text: 'ID', dataIndex:'id',filterable: true}
],
width: 1000,
forceFit: true,
});
var frmTrailerPanel = Ext.create('Ext.form.Panel', {
title: 'Hashtag Form',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
itemId:'hashtag',
name: 'hashtag',
fieldLabel: 'Enter Hashtag',
allowBlank: false // requires a non-empty value
}
],
//renderTo:ext.getBody(),
buttons: [{
text: 'Search',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: '../../assignment/index.php',
waitMsg: 'Fetching tweets...',
success: function(form, action) {
},
failure: function(form, action) {
var myData = Ext.JSON.decode(action.response.responseText);
v.loadRawData(myData,true);
trailerPanel.render(Ext.getBody());
}
});
}
}
}
]
});
Output:
That is because all 5 have the same id value.
Related
Ext.define('Form', {
extend: 'Ext.data.Model',
fields: [
{name:'type', type:'String'}
]
});
var store = Ext.create('Ext.data.ArrayStore', {
model: 'Form',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/test.json',
reader: {
type : 'json',
root: 'types'
}
}
});
Ext.define('DForms', {
extend: 'Ext.panel.Panel',
bodyPadding: 12,
layout : 'auto',
autoScroll : true,
items: [{
xtype:'selectcombo',
queryMode:'local',
emptyText: 'Select Condition',
store:store,
displayField: 'type',
valueField: 'type',
width : 200,
typeAhead : true
}],
});
When this loads, the selectcombo is empty, nothing gets loaded, i have searched through many sites, and can't find anything to help. Any suggestions would be great
The xtype you look for is combo, the store type is JsonStore because the ArrayStore will not interpret the json from the types root as you might expect. I can not simulate the ajax request here though.
Ext.onReady(function() {
Ext.define('Form', {
extend: 'Ext.data.Model',
fields: [{
name: 'type',
type: 'String'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'Form',
data: [{
type: 'Aaaaaaa'
}, {
type: 'Bbbbbb'
}, {
type: 'Ccccccccccc'
}, {
type: 'Ddddddd'
}]
});
Ext.define('DForms', {
extend: 'Ext.panel.Panel',
bodyPadding: 12,
layout: 'auto',
autoScroll: true,
items: [{
xtype: 'combo',
queryMode: 'local',
emptyText: 'Select Condition',
store: store,
displayField: 'type',
valueField: 'type',
width: 200,
typeAhead: true
}],
});
Ext.create('DForms', {
renderTo: Ext.getBody()
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all-debug.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all.css" />
I think type in fields is case-sensitive. So try
fields :[{name : 'type', type : 'string'}]
If still not working, as Tejas1991 pointed out check the content of your json.
I have defined Ext.tree.Panel and on change of combo value, I am calling
tree.getStore().load();
Here is my treepanel code
Ext.define('InboxTreePanel', {
extend: 'Ext.tree.Panel',
xtype: 'inboxtreepanel',
height: 250,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
store: Ext.create('Ext.data.TreeStore', {
fields: [{
name: 'id',
type: 'string'
}, {
name: 'text',
type: 'string'
}],
autoLoad: false,
proxy: {
type: 'jsonajax',
url: app_global.serviceExtn + 'browseS3.do',
reader: {
type: 'json',
root: 'results'
}
},
root: {
loaded: false
}
}),
columns: [{
xtype: 'treecolumn',
dataIndex: 'text',
flex: 1,
text: 'Nodes',
editor: 'textfield'
}]
});
me.callParent(arguments);
}
});
In return I am getting json data but data is not loading in treepanel
{"success":true,
"code":null,
"message":null,
"data":[{"id":"root/Date-2015-08-30","text":"Date-2015-08-30","leaf":false},
{"id":"root/Date-2015-08-31","text":"Date-2015-08-31","leaf":false},
{"id":"root/Date-2015-09-08","text":"Date-2015-09-08","leaf":false},
{"id":"root/Date-2015-09-09","text":"Date-2015-09-09","leaf":false}],
"totalCount":0}
Can anyone help why data is not loading in treepanel? What is wrong in my code
Unable to show JSON data into Grid. I got blank grid but you can see sequence no "1" and blank row, though number 1 is auto generated, it is not a JSON data.
code
Ext.onReady(function(){
// PRESSURE GRID - PRESSURE TAB //
var proxy=new Ext.data.HttpProxy( {url:'',method: 'POST'} );
Ext.define('pressureModel', {
extend: 'Ext.data.Model',
fields: ['month', 'KOD', 'timePeriod', 'beachBank', 'manMade', 'charterBoat', 'privateRentalBoat']
});
var pressureGridStore=new Ext.data.Store({
id: "pressureG",
model: 'pressureModel',
proxy: proxy,
reader:new Ext.data.JsonReader({
type : 'json',
root: 'pressureFi',
totalProperty: 'pressureResultLength'
},[{name:'month'},{name:'KOD'},{name:'timePeriod'},{name:'beachBank'},{name:'manMade'},{name:'charterBoat'},{name:'privateRentalBoat'}]
)
});
// Generic fields array to use in both store defs.
var pressureFields = [
{name: 'month', mapping: 'month', type: 'string'},
{name: 'KOD', mapping: 'KOD', type: 'string'},
{name: 'timePeriod', mapping: 'timePeriod', type: 'string'},
{name: 'beachBank', mapping: 'beachBank', type: 'string'},
{name: 'manMade', mapping: 'manMade', type: 'string'},
{name: 'charterBoat', mapping: 'charterBoat', type: 'string'},
{name: 'privateRentalBoat', mapping: 'privateRentalBoat', type: 'string'}
];
var pressureGrid = new Ext.grid.GridPanel({
id : "pressure-grid",
ddGroup : 'gridDDGroup',
store : pressureGridStore,
columns: [new Ext.grid.RowNumberer(),
{
text: 'Month',
width: 70,
dataIndex: 'month'
},{
text: 'Kind of Day',
width: 85,
dataIndex: 'KOD'
},{
text: 'Time Period',
width: 95,
dataIndex: 'month'
},{
text: 'Beach/Bank',
width: 65,
dataIndex: 'beachBank'
},{
text: 'Man/Made',
width: 65,
dataIndex: 'manMade'
},{
text: 'Charter Boat',
width: 75,
dataIndex: 'charterBoat'
},{
text: 'Private/Rental Boat',
width: 105,
dataIndex: 'privateRentalBoat'
}],
enableDragDrop : true,
stripeRows : true,
autoExpandColumn : 'name',
width : 624,
height : 325
});
function handleActivate(tab){ alert("in handle ");
pressureGridStore.proxy.url='siteUtil.jsp';
pressureGridStore.load({params:
{'method':'getSitePressureInfo'}
});
}
tabPanelObject = {
getTabPanel: function(siteId) {
var infoPanel = new Ext.tab.Panel({
id: 'tabPan',
xtype: 'tabpanel',
title: 'Site Information',
height: 1000,
width: '50.4%',
items:[
{
title: 'Pressure',
id: 'pressureTab',
listeners: {activate: handleActivate},
items:[
{
xtype: "panel",
width : '100%',
height : 300,
layout: 'fit',
items: [
pressureGrid
] }
]}
]
});
return infoPanel;
}
}
});
Json Response is as follow
{"pressureResultLength":"96","pressureFi":[{"charterBoat":9,"timePeriod":"0200- 0800","KOD":"WEEKDAY","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9}, {"charterBoat":0,"timePeriod":"0800-1400","KOD":"WEEKDAY","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"1400-2000","KOD":"WEEKDAY","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"2000-0200","KOD":"WEEKDAY","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"0200-0800","KOD":"WEEKEND","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"0800-1400","KOD":"WEEKEND","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"1400-2000","KOD":"WEEKEND","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"2000-0200","KOD":"WEEKEND","beachBank":9,"month":"JAN","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"0200-0800","KOD":"WEEKDAY","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"0800-1400","KOD":"WEEKDAY","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"1400-2000","KOD":"WEEKDAY","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"2000-0200","KOD":"WEEKDAY","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"0200-0800","KOD":"WEEKEND","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"0800-1400","KOD":"WEEKEND","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":0,"timePeriod":"1400-2000","KOD":"WEEKEND","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"2000-0200","KOD":"WEEKEND","beachBank":9,"month":"FEB","privateRentalBoat":9,"manMade":9},{"charterBoat":9,"timePeriod":"0200-0800","KOD":"WEEKDAY","beachBank":9,"month":"MAR","privateRentalBoat":9,"manMade":9}]}
I checked the FireBug Console. It returns the response as above but it is of type(actionmethod) 'GET'
When I did
pressureGridStore.on({
'load':{
fn: function(store, records, options){
//store is loaded, now you can work with it's records, etc.
console.info('store load, arguments:', arguments);
console.info('Store count = ', store.getCount());
},
scope:this
}
});
I got Store Count = 1.
-Ankit
the problem is that your components aren't defined correctly. for instance, the reader config in extjs4 doesn't belong to store, it belongs to proxy see http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/api/Ext.data.proxy.Ajax so for the proxy you should have
var proxy=new Ext.data.HttpProxy( {
url:'',
reader:new Ext.data.JsonReader({
type : 'json',
root: 'pressureFi',
totalProperty: 'pressureResultLength'
})
})
I think with this modification it should work
I try to load fields config to json store via metadata. The json is:
{
"rows":[
{
"datev":"02.01.2011",
"w1":"100",
"w2":"200"
},
{
"datev":"02.01.2011",
"w1":"300",
"w2":"50"
},
{
"datev":"03.01.2011",
"w1":"10",
"w2":"450"
}
],
"metaData":{
"fields":[
{
"name":"datev"
}
],
"root":"rows"
}
}
and my store is:
var test = new Ext.data.JsonStore({
url: 'test.php'
});
test.load();
The metadata doesn't load. What is wrong with the code?
I think you need to add a JSON reader
var reader = new Ext.data.JsonReader({
fields: []
});
var store = new Ext.data.Store({
nocache : true,
reader : reader,
autoLoad : true,
remoteSort : true,
proxy : new Ext.data.HttpProxy({
url : '/getjson?queryable=featureType&featureType=Electronic%20Device',
method : 'GET'
})
or maybe
var store = new Ext.data.JsonStore({
url: 'somewhere',
fields: []
});
You are not specifying the Id Property, and neither the Root property. this is my code i hope this help
var EStore = new Ext.data.JsonStore
({
api: { read: 'getAssignedJobs',
create: 'createAssignedJobs',
update: 'updateAssignedJobs'
},
root: 'jobData',
idProperty: 'Id',
autoSave: true,
batch: false,
successProperty: 'success',
writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
fields: [
{ name: 'Id', type: 'int' },
{ name: 'ResourceId', mapping: 'fitter_id', type: 'int' },
{ name: 'StartDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'EndDate', type: 'date', format: 'd/m/Y G:i' },
{ name: 'status', type: 'int' },
{ name: 'job_id', type: 'int' }
]
});
This is driving me insane. I have a JS file that is:
Ext.onReady(function(){
Ext.QuickTips.init();
var SitesStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [{
name: 'id',
mapping: 'id'
}, {
name: 'name',
mapping: 'name'
}],
proxy: {
type: 'ajax',
url : '/sites/getsites.do'
},
storeId: 'SitesStore',
root: 'sites',
url: '/sites/getsites.do',
xtype: 'jsonstore'
});
SitesStore.load(function(data){
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Site...',
store: SitesStore,
data: data[0].raw["sites"],
queryMode: 'remote',
displayField: 'name',
valueField: 'id',
renderTo: "timesheetSearch"
});
console.log(data[0].raw["sites"]);
});
}); //end onReady
My /sites/getsites.do returns JSON data in the following format:
{
-sites: [
-{
id: "12345678"
name: "Blah Warehouse"
},
-{
id: "5999B91DF6C0"
name: "WalMart Warehouse"
},
...
}
I realize the data[0].raw["sites"] probably isn't the preferred way to access the data but I do confirm that the data is being populated and I'm getting back 136 sites.
The combobox DOES render. However, the live search doesn't work and there are no entries.
I'm new to ExtJS.
Any tips would be appreciated.
Thanks
UPDATE
This code WORKS
var SitesStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
data: [{'id':'aaaa', 'name':'Honeywell'}],
storeId: 'SitesStore',
root: 'sites'
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Site...',
store: SitesStore,
queryMode: 'remote',
displayField: 'name',
triggerAction: 'all',
valueField: 'id',
renderTo: "timesheetSearch"
});
This does NOT
var SitesStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
proxy: {
type: 'ajax',
url: '/sites/getsites.do'
},
storeId: 'SitesStore',
root: 'sites'
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Site...',
store: SitesStore,
queryMode: 'remote',
displayField: 'name',
triggerAction: 'all',
valueField: 'id',
renderTo: "timesheetSearch"
});
When I run it without a proxy (and specify a url) I get an error saying I didn't specify a proxy.
Thanks
UPDATE
UGH!!!!!!
I got it. Here is the correct JSONStore
var SitesStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
proxy: {
type: 'ajax',
url: '/sites/getsites.do',
reader: {
type:'json',
root: 'sites'
}
},
storeId: 'SitesStore',
root: 'sites'
});
Thanks everyone. Couldn't believe how hard this was. Mainly because I couldn't find a good tutorial. lol
UPDATE
I was able to figure this out. Here is the working code:
var SitesStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
proxy: {
type: 'ajax',
url: '/sites/getsites.do',
reader: {
type:'json',
root: 'sites'
}
},
storeId: 'SitesStore',
root: 'sites'
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Site...',
store: SitesStore,
queryMode: 'remote',
displayField: 'name',
triggerAction: 'all',
valueField: 'id',
renderTo: "timesheetSearch"
});
I never could get JSONStore to work so I created a standard Store and had to match the reader attribute with my JSON data.
Hope this helps someone.
That's a bit dirty and my first ExtJS4 lines (I am used to v2.x/3.x) but it should work. As I see you use a browser with console so you will be able to debug if there are some errors. Also you should take a look at the API
var SitesStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [{
name: 'id',
mapping: 'id'
}, {
name: 'name',
mapping: 'name'
}],
proxy: {
type: 'ajax',
url : '/sites/getsites.do'
},
storeId: 'SitesStore',
root: 'sites',
url: '/sites/getsites.do'
// ,xtype: 'jsonstore'
});
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose Site...',
store: SitesStore,
// data: data[0].raw["sites"],
queryMode: 'remote',
displayField: 'name',
valueField: 'id',
renderTo: "timesheetSearch",
listeners:{
scope: this,
'select': function(field, value){
console.log(value);
}
}
});
});