Extjs 4 combo xml store load? - extjs

I am using ext-4.2.1, below is the code. It has two problems, (1) buildCategoryStore(), combo can't find the store. (2) the below is the xml data, looks like the store xml reader doesn't work, how to set up the xml root ?
Thanks
Ext.define('App.view.QuestionForm',{
extend : 'Ext.form.Panel',
alias : 'widget.QuestionForm',
requires : [],
initComponent : function(){
var me = this;
me.items = me.buildItems();
me.callParent();
},
buildCategoryStore: function(){
var CategoryStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['id','name'],
proxy: {
type: 'ajax',
url: 'rs/question/getAllCategories',
reader: {
type:'xml',
root: 'CategoryList'
}
},
storeId: 'CategoryStore',
root: 'CategoryList'
});
return CategoryStore;
},
buildItems : function(){
return [
{
xtype: 'combo',
anchor: '100%',
fieldLabel : 'Category',
store: buildCategoryStore(),
name: 'category',
mode: 'local',
multiSelect: false
},
];
},
}
});
xml data :
<CategoryList>
<Category>
<active>Y</active>
<id>1000</id>
<name>Life</name>
<versionNum>0</versionNum>
</Category>
<Category>
<active>Y</active>
<id>1001</id>
<name>Career</name>
<versionNum>0</versionNum>
</Category>
</CategoryList>

I've fixed up your code. The important parts are you need to call this.foo() and you need to specify the record param for the reader.
Ext.define('App.view.QuestionForm', {
extend: 'Ext.form.Panel',
alias: 'widget.QuestionForm',
requires: [
'Ext.data.Store'
],
initComponent: function() {
this.items = this.buildItems();
this.callParent();
},
buildCategoryStore: function() {
return new Ext.data.Store({
autoLoad: true,
fields: ['id', 'name'],
proxy: {
type: 'ajax',
url: 'rs/question/getAllCategories',
reader: {
type: 'xml',
record: 'Category'
}
}
});
},
buildItems: function() {
return [{
xtype: 'combo',
anchor: '100%',
fieldLabel: 'Category',
store: this.buildCategoryStore(),
name: 'category',
mode: 'local',
multiSelect: false,
valueField: 'id',
displayField: 'name'
}];
}
});

Related

ExtJS 6 - Bind proxy data to form

I have a proxy store that retrieves information from a webservice, I would like to show that information in a Panel in a way like a Grid, in which I set the "dataIndex" parameter to bind in the retrieved data.
How can I achieve this goal without extra coding, is that possible?
Something like this:
Proxy Store:
Ext.define('MyStore', {
extend: 'Ext.data.Store',
alias: 'store.myStore',
model: 'myModel',
autoload: true,
proxy: {
type: <wsType>,
url: <wsUrl>
},
scope: this
});
Panel:
Ext.define('<myPanel>', {
extend: 'Ext.panel.Panel',
...
store: Ext.create(<myStore>),
...
items: [
{
xtype: 'titlePanel',
cls: 'titlePanel',
html: '<div class="titlePanel"><h1>My Title</h1></div>',
},
{
xtype: 'form',
layout: 'vbox',
cls: 'whitePanel',
items: [
{
xtype: 'panel',
layout: 'column',
items: [
{
xtype: 'displayfield',
displayField: 'name',
dataIndex: 'name',
fieldLabel: Ext.locale.start,
name: 'start'
},
...
You don't need Store for displaying a single Record. Proxy can be defined at a model level.
Ext.define('MyApp.model.Contact', {
extend: 'Ext.data.Model',
fields: ['id', 'firstName', 'middleName', 'lastName'],
proxy: {
type: 'ajax',
url: 'contacts.json',
reader: {
type: 'json',
rootProperty: 'data'
}
}
});
Load the model either in view constructor/initComponent or controller init method, once loaded push the record to ViewModel.
initComponent: function() {
this.callParent(arguments);
var me = this;
MyApp.model.Contact.load(1, {
success: function(record, operation) {
me.getViewModel().set('contact', record);
}
})
},
Bind the model property to the display field
items: [{
name: 'firstName',
fieldLabel: 'First Name',
bind: '{contact.firstName}',
xtype: 'displayfield'
}]
And here is the fiddle
https://fiddle.sencha.com/#fiddle/17t2

RowEditing with Combobox - changes (click row editing) - should be displayed "displayField"

RowEditing with Combobox - changes (click row editing) shown "id",
should be displayed "displayField"
pic - i65.fastpic.ru/big/2014/0724/46/d7cef656f6d993bc17657486ba5b6b46.gif
when editing a row - to display the value of the field displayfield from storeServer
now displays dataindex from store
Ext.define('ModelLib', {
extend: 'Ext.data.Model',
fields: [
'trID',
'trName'
]
});
var storeServer = Ext.create('Ext.data.Store', {
autoDestroy: true,
model: 'ModelLib',
proxy: {
type: 'ajax',
api: {
read: '/api.php?lib=server&act=get'
},
reader: {
type: 'json',
root: 'fields',
idProperty: "trID"
}
},
sorters: [{
property: 'trID',
direction: 'ASC'
}]
});
storeServer.load();
Ext.define('ModelMainobjects', {
extend: 'Ext.data.Model',
fields: [
{name: 'trServerID', type: 'int'}
]
});
var store = Ext.create('Ext.data.Store', {
// destroy the store if the grid is destroyed
autoDestroy: true,
autoSync : true,
model: 'ModelMainobjects',
proxy: {
type: 'ajax',
api: {
read: '/api.php?lib=mainobjects&act=get',
update: '/api.php?lib=mainobjects&act=update'
},
reader: {
type: 'json',
root: 'fields',
idProperty: "trID"
},
writer: {
type: 'json'
}
},
sorters: [{
property: 'trID',
direction: 'ASC'
}]
});
store.load();
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
var rowRenderer = function(val) {
var rec = storeServer.findRecord('id', val);
return rec !== null ? rec.get("trName") : ''
};
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{
header: 'Сервер',
dataIndex: 'trServerID',
renderer: rowRenderer,
editor: {
xtype: 'combobox',
store: storeServer,
queryMode: 'local',
displayField: 'trName',
valueField: 'trID'
}
}],
width: 600,
height: 400,
plugins: [rowEditing]
});

sencha touch 2 how create url dynamic store from item list

I need to pass the value of selected item in the list to a list of detail to load data from a store.
The code view is
Ext.define('App.view.PresidentList', {
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.Presidents','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'Presidents',
onItemDisclosure: true,
}
});
The code controller is
Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
main: 'mainpanel'
},
control: {
'presidentlist': {
disclose: 'showDetail'
}
}
},
showDetail: function(list, record) {
var listItems = Ext.create('App.store.ListItems', {newUrl : record.getData()});
listItems.load();
this.getMain().push({
xtype: 'presidentdetail',
title: record.fullName(),
data: record.getData(),
store: listItems
});
}
});
the code view datail is
Ext.define('App.view.PresidentDetail', {
extend: 'Ext.tab.Panel',
xtype: 'presidentdetail',
config: {
title: 'Details',
scrollable: 'vertical',
items:
[
{
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.ListItems','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'ListItems',
onItemDisclosure: true,
}
},
{
xtype: 'nestedlist',
title: 'Contactos',
id: 'panel2',
useToolbar:false,
displayField: 'title',
store: {
type: 'tree',
fields: [
'title','link','author','contentSnippet','content',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog/',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
},
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
itemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('content'));
}
}
},
{
xtype: 'panel',
id: 'panel5',
title: 'Costos',
iconCls: 'home'
},
{
xtype: 'panel',
title: 'Otros',
iconCls: 'favorites',
id: 'panel5'
},
]
}
});
and the code store of ListItems is
Ext.define('App.store.ListItems',{
extend: 'Ext.data.Store',
autoLoad: true,
config: {
model: 'App.model.President',
proxy: {
//autoLoad: true,
type: 'ajax',
url:<-------->here comes the url with the variable that is passed from the list
reader: {
type: 'json',
rootProperty: "test"
}
}
}
});
Please collaboration with this issue not to do this. thank you very much.
If you just want to change the url of the proxy on a store, you can do like this
Ext.getStore('YourStoreId').getProxy().setUrl("your_new_url");
Ext.getStore('YourStoreId').load();
You must use estraParams inside the proxy
extraParams:{Parm1:2, Parm2:'eeee'},

ExtJs- TreeStore AJAX Proxy not sending request to Server or TreeStore is not loading

Ext js TreeStore is not loading
Ext.ns('App');
Ext.onReady(function() {
Ext.QuickTips.init();
App.PPPExplorer.init();
});
App.PPPExplorer = {
// Initialize application
init : function(serverCfg) {
this.PPP = this.createPPP();
},
createPPP : function() {
// Set up a model to use in our Store
Ext.define('Summary', {
extend: 'Ext.data.Model',
fields: [
{name: 'pid', type: 'string'}
]
});
var myStore = Ext.create('Ext.data.TreeStore', {
model: 'Summary',
storeId:'myStore',
proxy: {
type : 'ajax',
method: 'GET',
url: '/Explorer.do?method=getPPP&search=true',
reader: {
type: 'json'
},
root: {
pid: 'src',
text:'test',
expanded: true
},
},
autoLoad: true
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: myStore,
// rootVisible: true,
renderTo: 'Explorer',
columns: [{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: 'Reference',
flex: 2,
sortable: true,
dataIndex: 'pid',
locked: true
}]
});
}
}
I am using Ext js 4.2 Version
I have used treeStore, treePanel in the above code, somehow Proxy call is not sent to Server. There was no error message in the console
Thanks in advance
Root definition should be inside TreeStore definition as follows (it's on the proxy declaration now):
var myStore = Ext.create('Ext.data.TreeStore', {
model: 'Summary',
storeId: 'myStore',
proxy: {
type: 'ajax',
method: 'GET',
url: '/Explorer.do?method=getPPP&search=true',
reader: {
type: 'json'
}
},
autoLoad: true,
root: {
pid: 'src',
text: 'test',
expanded: true
}
});
That way your code works, you can see it here

extjs combo box not binding to array store

Using the example in "ext-designer-for-ext-js-4-users-guide.pdf" i've put together the following. The issue is that the store is not binding. ie the select is empty.
MyComboBox.js
Ext.define('MyApp.view.MyComboBox', {
extend: 'MyApp.view.ui.MyComboBox',
initComponent: function() {
var me = this;
me.callParent(arguments);
}
});
Ext.define('MyApp.view.ui.MyComboBox', {
extend: 'Ext.form.field.ComboBox',
fieldLabel: 'comboList',
displayField: 'comboList',
queryMode: 'local',
store: 'MyArrayStore',
triggerAction: 'all',
valueField: 'comboList',
initComponent: function() {
var me = this;
me.callParent(arguments);
}
});
store/MyArrayStore.js
Ext.define('MyApp.store.MyArrayStore', {
extend: 'Ext.data.Store',
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'MyArrayStore',
data: [
[
'Search Engine'
],
[
'Online Ad'
],
[
'Facebook'
]
],
proxy: {
type: 'ajax',
reader: {
type: 'array'
}
},
fields: [
{
name: 'comboList'
}
]
}, cfg)]);
}
});
** update **
this was driving me crazy. It's [turns out][1] my array need to be json format. When i updated it to
[{"comboList" : "Hello"}, {"comboList" : "Hi"}, {"comboList" : "GoodMorning"}]
it worked.
I started to try and pick apart your implementation but it seems somewhat convoluted, starting with the store where there is local data and a proxy defined but no url for the proxy.
It seemed easier to just give you a simplified implementation of a combobox (using local data because it seems that is what you are trying to do):
// the datastore
var myStore = Ext.create('Ext.data.Store', {
fields: ['value', 'name'],
data: [
{value: 1, name: 'Search Engine'},
{value: 2, name: 'Online Ad'},
{value: 3, name: 'Facebook'}
]
});
// a window to hold the combobox inside of a form
myWindow = Ext.create('Ext.Window', {
title: 'A Simple Window',
width: 300,
constrain: true,
modal: true,
layout: 'fit',
items: [{
// the form to hold the combobox
xtype: 'form',
border: false,
fieldDefaults: {
labelWidth: 75
},
bodyPadding: '15 10 10 10',
items: [{
// the combobox
xtype: 'combo',
id: 'myCombo',
fieldLabel: 'Title',
valueField: 'value',
displayField: 'name',
store: myStore,
queryMode: 'local',
typeAhead: true,
forceSelection: true,
allowBlank: false,
anchor: '100%'
},{
// shows the selected value when pressed
xtype: 'button',
margin: '10 0 0 100',
text: 'OK',
handler: function() {
alert('Name: ' + Ext.getCmp('myCombo').getRawValue() +
'\nValue: ' + Ext.getCmp('myCombo').value);
}
}]
}]
});
// show the window
myWindow.show();
This creates a combobox inside of a little window with an OK button. When you press OK it will alert the visible text of the combobox Ext.getCmp('myCombo').getRawValue() and the value of the item in the combobox Ext.getCmp('myCombo').value.
If you drop this in your project you can get an idea of how it implements, it should just run.
If you actually wanted a remote datastore (from a webservice that returns json for example) you would just need to change the datastore configuration like so:
var myRemoteStore = Ext.create('Ext.data.Store', {
fields: ['value', 'name'],
proxy: {
type: 'ajax',
url: 'myWebservice.php', // whatever your webservice path is
reader: 'json',
},
autoLoad:true
});

Resources