error while loading the store associated with the gridpanel - extjs

Ext.define('MyApp.controller.Main', {
extend: 'Ext.app.Controller',
models: [
'User'
],
stores: [
'userStore'
],
refs: [
{
ref: 'navigation',
selector: 'navigation'
},
{
ref: 'ContentPanel',
selector: 'ContentPanel'
},
{
ref: 'viewport',
selector: 'viewport'
},
{
autoCreate: true,
ref: 'myForm',
selector: 'MyForm',
xtype: 'MyForm'
},
{
autoCreate: true,
ref: 'usergrid',
selector: 'usergrid',
xtype: 'userGrid'
}
],
onSaveButtonClick(button,e,eopts){ var form1 = this.getMyForm();
if(form1.isValid())
{
var form = form1.getForm();
user= this.getUserModel().create(
{
firstName: form.findField('firstName').getValue(),
midName: form.findField('midName').getValue(),
lastName: form.findField('lastName').getValue(),
gender: form.findField('gender').getValue(),
age: form.findField('age').getValue(),
buildingName: form.findField('buildingName').getValue(),
street: form.findField('streetName').getValue(),
country: form.findField('country').getValue(),
pinCode: form.findField('pinCode').getValue(),
state: form.findField('state').getValue()
});
debugger;
var store= this.getUserStoreStore();
store.data.add(user);
var List= this.getUsergrid();
List.getStore().load();
var contentPanel = this.getContentPanel();
contentPanel.removeAll(true);
contentPanel.add(List);
form1.close();
alert('Data stored Successfully');
}
else
{
alert('Few Datas are missing!!');
}
//Store
Ext.define('MyApp.store.userStore', {
extend: 'Ext.data.Store',
alias: 'store.userStore',
requires: [
'MyApp.model.User'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'MyApp.model.User',
storeId: 'userStore',
proxy: {
type: 'ajax',
reader: {
type: 'json'
}
}
}, cfg)]);
}
});

Your code is incorrect for 2 reasons:
1) You should not be modifying the underlying data collection. If it's giving an error, then something else is wrong.
2) If you're loading the store, why are you adding items to it? It should already be loaded.

Related

ExtJS TreeStore is empty if I load store by manually

Model
Ext.define('MyDesktop.model.mail.MailFoldersModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.String'
],
fields: [
{
type: 'string',
name: 'id'
},
{
type: 'string',
name: 'idParent'
},
{
type: 'string',
name: 'text'
}
]
});
My TreeStore
Ext.define('MyDesktop.store.mail.MailFoldersStore', {
extend: 'Ext.data.TreeStore',
requires: [
'MyDesktop.model.mail.MailFoldersModel'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MailFoldersStore',
model: 'MyDesktop.model.mail.MailFoldersModel',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://url/mail/folders',
reader: {
type: 'json',
rootProperty: 'items',
successProperty: 'success'
}
},
root: {
text: 'root',
iconCls: 'mail-folders-owner'
}
}, cfg)]);
}
});
Store is autoloaded, all works correctly, store contains 11 records.
var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
storeId: 'MailFoldersStore'
});
If I set autoLoad to false and trying to load by manually - store is empty, 0 records.
var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
storeId: 'MailFoldersStore'
});
MailFoldersStore.load({
callback : function(records, operation, success) {
console.log(records);
}
});
What can be a reason for this behaviour?
I also has same problem. I am using Extjs 5.1. After googling I found one complex solution which needs us to modify the framework.
See the below link if it can help you.
http://www.sencha.com/forum/showthread.php?154823-listeners-quot-exception-quot-in-proxy.ajax-on-TreeStore-do-not-work

sencha touch 2: list population with associations in model

as a learning project for sencha-touch2 i'm trying to populate a store with data from https://www.hnsearch.com/api
i have created the model and store as follow and in the inspector view i can see that data is received and correctly mapped.
the problem i cannot figure out is, how to show a sencha xtype:list element with the actual result items nested in the json (Model: SearchResultItem). i tried the following, which will give me a list with ONE list item with the results in it, but i would like to have a list item for each search result.
models:
Ext.define('senchaHackerNews.model.Search', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'hits',
type: 'int'
}],
associations: {
type: 'hasMany',
name: 'results',
model: 'senchaHackerNews.model.SearchResults',
associationKey: 'results'
}
}
});
Ext.define('senchaHackerNews.model.SearchResults', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'score',
type: 'float'
}],
associations: {
type: 'hasOne',
name: 'item',
model: 'senchaHackerNews.model.SearchResultItem',
associationKey: 'item'
}
}
});
Ext.define('senchaHackerNews.model.SearchResultItem', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'username',
type: 'string'
}, {
name: 'title',
type: 'string'
}, {
name: 'points',
type: 'int'
}, {
name: 'url',
type: 'string'
}, {
name: 'domain',
type: 'string'
}]
}
});
store:
Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.Search'],
config: {
storeId: 'hnSearchStore',
model: 'senchaHackerNews.model.Search',
autoload: false,
proxy: {
type: 'jsonp',
// url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
reader: {
type: 'json',
rootProperty: ''
},
callbackKey: 'callback'
}
}
});
view:
Ext.define('senchaHackerNews.view.Search', {
extend: 'Ext.navigation.View',
alias: 'widget.hnSearch',
xtype: 'hnSearch',
requires: ['Ext.field.Search'],
initialize: function() {
var xtpl = new Ext.XTemplate('<tpl for="results">{item.username} ---- {item.title} | <br></tpl>');
this.add([
{
xtype: 'container',
title: 'Search HN',
layout: 'vbox',
items: [{
xtype: 'searchfield',
placeHolder: 'Search HN News (at least 3 chars)',
listeners: {
scope: this,
clearicontap: this.onSearchClearIconTap,
keyup: this.onSearchKeyUp
}
}, {
xtype: 'list',
flex: 1,
itemTpl: xtpl,
store: 'hnSearchStore',
emptyText: 'No Matching Items',
}]
}
]);
this.callParent(arguments);
},
onSearchKeyUp: function(field) {
if(field.getValue() != '' && field.getValue().length > 3) {
var store = Ext.StoreMgr.get('hnSearchStore');
store.setProxy({
url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q='+field.getValue()
});
store.load();
} else if(field.getValue() == '') {
Ext.StoreMgr.get('hnSearchStore').removeAll();
}
},
onSearchClearIconTap: function() {
Ext.StoreMgr.get('hnSearchStore').removeAll();
}
});
Example JSON is here http://api.thriftdb.com/api.hnsearch.com/items/_search?q=facebook&pretty_print=true
AFAIK if you are looking for array of items to be displayed the you should use items model in store and rootProperty pointing to item so
Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.SearchResults'],
config: {
storeId: 'hnSearchStore',
model: 'senchaHackerNews.model.SearchResults',
autoload: false,
proxy: {
type: 'jsonp',
// url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
reader: {
type: 'json',
rootProperty: 'results'
},
callbackKey: 'callback'
}
}
});
Note the change in model & rootProperty attribute

Call function in ExtJs TreeStore

How can I access the function getTree in my TreeStore-Instance from the configuration of the DirectProxy? Like this etc. nothing works....
Is somebody able to help me?
Ext.define('PM.store.Projects', {
extend: 'Ext.data.TreeStore',
model: 'PM.model.Project',
autoLoad: true,
/*proxy: {
type: 'ajax',
url: 'data/projectTree.json',
reader: {
type: 'json',
},
},
root: {
name: 'Test',
id: -1,
}*/
proxy: {
type: 'direct',
directFn: PM.controller.Projects.getTree,
},
/*root: {
name: 'Demo',
children: [
{
name: 'Test',
leaf: true,
},
],
},*/
getTree: function() {
alert("Test");
}
});
You can build you proxy in the constructor I suppose.
Ext.define('PM.store.Projects', {
extend: 'Ext.data.TreeStore',
model: 'PM.model.Project',
autoLoad: true,
constructor: function(config) {
var me = this;
Ext.apply(me, config);
me.proxy = {
type: 'direct',
directFn: me.getTree
};
me.callParent();
},
getTree: function() {
alert("Test");
}
});

how to move data from one page to another page in Senchatouch

I am developing one application in sencha touch, I am new to this technology
first see my code
View-->Main.js
Ext.define('DealsList.view.Main', {
extend: 'Ext.Container',
xtype: 'mainlist',
requires: [
'Ext.TitleBar',
'Ext.Toolbar'
],
config: {
fullscreen:true,
scrollable:false,
layout: {
// type:'fit'
},
items: [
{
xtype: 'toolbar',
//ui : 'green',
docked: 'top',
title: 'SampleDeals'
},
{
xtype:'formpanel',
fullscreen:false,
scrollable:false,
centered:true,
style: 'background-color: gray',
width:'90%',
height:'70%',
items:[
{
xtype:'selectfield',
name:'Grade',
label:'Grade',
options:[
{
text:'All',
value:'Agrade'
},
{
text:'Drink',
value:'Bgrade'
},
{
text:'Entertainment',
value:'cgrade'
},
{
text:'Food',
value:'Dgrade'
}
]
},
{
xtype:'searchfield',
id:'usernametext',
name:'ZipCode',
placeHolder:'ZipCode',
top:'25%'
},
{
xtype:'button',
text:'Gps On/Off',
id:'btnList',
ui:'action',
height:33,
top:'40%',
left:'5%',
right:'5%'
},
{
xtype:'selectfield',
name:'Grade',
label:'Grade',
top:'55%',
options:[
{
text:'2 miles',
value:'Agrade'
},
{
text:'5 miles',
value:'Bgrade'
},
{
text:'10 miles',
value:'cgrade'
},
{
text:'15+ miles',
value:'Dgrade'
}
]
},
{
xtype:'button',
text:'My Favorites',
id:'favbutton',
ui:'action',
width:150,
height:33,
top:'75%',
left:'5%'
}
,{
xtype:'button',
text:'Go',
id:'gobutton',
ui:'action',
width:100,
height:33,
top:'75%',
right:'5%',
handler:this.regButton,
scope:this
}
]
}
]
}
});
view-->ListPage.js
Ext.define('DealsList.view.ListPage', {
extend: 'Ext.List',
xtype: 'listPage',
requires:['Ext.data.Store','Ext.dataview.List','Ext.data.proxy.JsonP'],
config: {
// itemTpl: '<table><tr><td><img src="{imageUrl}" width="70%" height="70%"/></td><td> </td><td><div class=\"list-item-firstname\">{firstName}</div><div class=\"list-item-lastname\">{lastName}</div></td></tr></table>',
itemTpl: ' <table><tr>' +
'<td><img src="{logopath}"/></td>' +
'<td> </td>' +
'<td><div><h3>{subcategoryname}</h3></div>' +
'<div><h1>{specialinfo}</h1></div>' +
'<div>Price:{originalprice}</div>' +
'<div><h1>{fromdate}</h1></div>' +
'</td></tr></table>',
store: 'DetailStore',
onItemDisclosure: true,
items:
[
{
xtype:'toolbar',
title:'SampleDeals',
docked:'top',
items:[
{
xtype:'button',
id:'backbutton',
ui:'back',
text:'back'
}
]
}
]
}
});
view-->DealsDescription.js
Ext.define('DealsList.view.DealsDescription', {
extend: 'Ext.Container',
xtype: 'dealsdescription',
requires:['Ext.Toolbar','Ext.field.Email','Ext.field.Password'],
config: {
fullscreen:true,
scrollable:false,
layout: {
// type:'fit'
},
items: [
{
xtype:'toolbar',
docked:'top',
title:'SampleDeals',
items:[
{
xtype:'button',
id:'backbutton',
ui:'back',
text:'back'
}
]
},
{
xtype:'label',
html: '<h1>{subcategoryname}</h1>'
//html: ["test test"].join("") '',
},
{
xtype:'label',
html: '<h1>{dealtimestampfrom}</h1>'
//html: ["test test"].join("") '',
},
{
xtype:'label',
html: '<h1>{specialinfo}</h1>'
//html: ["test test"].join("") '',
},
{
xtype:'label',
html: '<h1>{originalprice}</h1>'
//html: ["test test"].join("") '',
},
{
xtype:'button',
text:'Button',
id:'xxxbutton',
ui:'action',
top:'30%',
left:'35%',
right:'35%',
handler:this.saveButton
}
]
}
});
Store-->DetailStore.js
Ext.define('DealsList.store.DetailStore', {
extend: 'Ext.data.Store',
config: {
model: 'DealsList.model.DetailModel',
autoLoad: true,
remoteFilter: true,
//sorters: 'leadid',
grouper: {
groupFn: function(record) {
// return record.get('user_id')[0];
return record.get('dealtimestampfrom')[0];
}
},
proxy: {
type: 'ajax',
//url: 'http://113.193.181.53:8081/Test/chat/index.php/chat/onlineusers',
url:'http://www.nomdeal.com/services/getbusinessoffers?catid=All&subcatid=All&lat=17.4418224&lng=78.4752594&dist=1000&userid=100&zipcode=&pagesize=1',
//headers: {'Authorization': 'Basic GVU0IXZ6cFGzczE='},
reader: {
type: 'json',
model: 'DealsList.model.DetailModel',
// rootProperty: 'online-users'
record:'businessholder',
rootProperty: 'specialinfo'
// rootProperty:''
}
}
}
});
Model-->DetailModel.js
Ext.define('DealsList.model.DetailModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: "dealtimestampfrom", type: "string"},
{name: "dealtimestampto", type: "string"},
{name: "subcategoryname", type: "string"},
{name: "specialinfo", type: "string"},
{name: "originalprice", type: "string"},
{name: "logopath", type: "string"},
{name: "fromdate", type: "string"}
]
}
});
Controller-->dealscontroller.js
Ext.define('DealsList.controller.dealscontroller', {
extend: 'Ext.app.Controller',
config: {
refs: {
BtnList:'#btnList',
listPage:'listPage',
mainpage:'mainlist',
backHome:'#backbutton',
goButton:'#gobutton',
DealsDescriptionpage:'dealsdescription'
},
control: {
goButton:
{
tap:'mainCategories'
},
backHome:
{
tap:'backToHome'
},
listPage:
{
itemtap: 'ListItemSelect'
}
}
},
// Transitions
slideLeftTransition: { type: 'slide', direction: 'left' },
slideRightTransition: { type: 'slide', direction: 'right' },
//called when the Application is launched, remove if not needed
launch: function(app) {
},
mainCategories:function()
{
//alert('sf');
Ext.Viewport.animateActiveItem(this.getListPage(), this.slideLeftTransition);
},
backToHome:function()
{
Ext.Viewport.animateActiveItem(this.getMainpage(), this.slideLeftTransition);
},
ListItemSelect : function (list, index, element, record)
{
Ext.Msg.alert('Alert',record.get('subcategoryname'));
Ext.Viewport.animateActiveItem(this.getDealsDescriptionpage(), this.slideLeftTransition);
}
});
app.js
//<debug>
Ext.Loader.setPath({
'Ext': 'touch/src',
'DealsList': 'app'
});
//</debug>
Ext.application({
controllers: ["dealscontroller"],
name: 'DealsList',
requires: [
'Ext.MessageBox'
],
views: ['Main','ListPage','DealsDescription'],
stores:['DetailStore'],
models:['DetailModel'],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function()
{
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
var mainPage = {
xtype:'mainlist'
};
var listpage = {
xtype:'listPage'
};
var dealsdescription = {
xtype:'dealsdescription'
};
// Initialize the main view
Ext.Viewport.add(([mainPage,listpage,dealsdescription]));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});
In my app's first screen I have a go button. When I click on this button it displays a list(listpage.js) my problem is, when I click on a listitem data is not moving to the nextpage(DealsDescription.js). My requrement is that the data moves to next page and is appended to that xtype:label(DealsDescription.js screen)
Most of us set up a one page application. So you switch cards (or tabs or so...) in staid of refreshing the page. This way you can always get to the data though javascript. Navigating up or down the component tree.
Up:
mycomponent.up() //go up one level
mycomponent.up(selector) //go up till you reach the component meeting the criteria
Down:
mycomponent.query(someComponentQuery) //go down and find all components meeting the criteria
mycomponent.getComponent(componentId) //get the (direct) child with given Id
If you do want to load a new page you need a whole new app.. So you could use session or local storage to transfer data between pages. (use a sessionstorageProxy or localstorageProxy on your store/model).
Basically you have to declare a data holder variable in view's config and while creating this view you can initialize it with whatever data you want.
var myView = Ext.create('DealsList.view.DealsDescription', {
rec : someData //this would contain all data
});
Then in initialize you can access this rec like this:
var data = this.config.rec;
then you can create all internal components and add to this view's container.
var items = [{
xtype:'toolbar',
docked:'top',
title:'SampleDeals',
items:[
{
xtype:'button',
id:'backbutton',
ui:'back',
text:'back'
}
]
},
{
xtype:'label',
html: '<h1>'+data.subcategoryname+'</h1>'
}];
this.setItems(items);

Sencha Touch Sync Stores

I have two stores: localstorage and a json on the server, I'm trying to download data from json to the local. Please see what's wrong:
/store/Notes.js
Ext.define("NotesApp.store.Notes", {
extend: "Ext.data.Store",
requires: "Ext.data.proxy.LocalStorage",
config: {
storeId: 'Notes',
model: "NotesApp.model.Note",
proxy: {
type: 'localstorage',
id: 'notes-app-store'
},
sorters: [{
property: 'dateCreated',
direction: 'DESC'
}],
grouper: {
sortProperty: "dateCreated",
direction: "DESC",
groupFn: function (record) {
if (record && record.data.dateCreated) {
return record.data.dateCreated.toDateString();
} else {
return '';
}
}
}
}
});
/store/Online.js
Ext.define("NotesApp.store.Online", {
extend: "Ext.data.Store",
config: {
storeId: 'Online',
proxy: {
type: 'jsonp',
url: 'http://server.com/made/qa.php',
reader: {
type: 'json'
//rootProperty: 'results'
}
},
autoLoad: false,
listeners: {
load: function() {
console.log("updating");
// Clear proxy from offline store
Ext.getStore('Notes').proxy.clear();
console.log("updating1");
// Loop through records and fill the offline store
this.each(function(record) {
console.log("updating2");
Ext.getStore('Notes').add(record.data);
});
// Sync the offline store
Ext.getStore('Notes').sync();
console.log("updating3");
// Remove data from online store
this.removeAll();
console.log("updated");
}
},
fields: [
{
name: 'id'
},
{
name: 'date_created'
},
{
name: 'question'
},
{
name: 'answer'
},
{
name: 'type'
},
{
name: 'author'
}
]
} });
When I need to update I called Ext.getStore('Online').load();
But the console is not showing anything else after 'updating'.
I wonder what went wrong?
Use Ext.getStore('Notes').getProxy().clear() instead works

Resources