Extjs treepicker error when reading from a json format - extjs

I'm still new in Extjs. I have a TreeStore which reads a JSON string as an input and I can represent it in a tree panel. But when I try to use the treestore in a tree picker there is get this error:
Is there anything missing here?
// try to find a record in the store that matches the value
record = value ? me.store.getNodeById(value) : me.store.getRootNode();
Here is the JSON format:
{
success: true,
"children": [
{
"id": "G_1",
"text": "group1",
"leaf": false
},
{
"id": "G_2",
"text": "group2",
"leaf": false
}
]
}
And here is my TreeStore:
Ext.define('App.store.GroupTree', {
extend: 'Ext.data.TreeStore',
model: 'App.model.GroupTree',
requires: 'App.model.GroupTree',
proxy: {
type: 'ajax',
url: 'property/tree.json',
reader: {
type: 'json',
root:'children'
}
},
});
My treepicker item:
items: [
{
xtype: 'treepicker',
name: 'propertyCmb',
fieldLabel: 'Property',
labelWidth: 60,
displayField: 'text',
store: 'GroupTree',
valueField: 'id',
queryMode: 'local',
}
]
Here is the treestore model code
Ext.define('App.model.GroupTree', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string', useNull: true},
{name: 'text', type: 'string'},
{name: 'leaf', type: 'boolean'},
{name: 'expanded', type: 'boolean'}
]
});

The error occurse, because the store is not auto created when assigned to your treepicker like store: 'GroupTree'.
You have to create an instance of it first and that instance you need to assign to the treepicker. See the documentation http://docs.sencha.com/extjs/5.0.1/#!/api/Ext.ux.TreePicker-cfg-store .
The following should work
var groupStore = Ext.create('App.store.GroupTree');
groupStore.load();
var picker = Ext.create('Ext.ux.TreePicker',{
name: 'propertyCmb',
store: groupStore,
fieldLabel: 'Property',
labelWidth: 60,
displayField: 'text',
valueField: 'id',
queryMode: 'local',
renderTo: Ext.getBody()
});
A working fiddle can be found at https://fiddle.sencha.com/#fiddle/dip .

Related

Chained combobox shows valuefield instead of displayfield when changing parent cb

How to reset chained combobox in my example the extjs way?
Consider this two comboboxes:
{
xtype: 'combo',
bind:{
store: '{contacts}'
},
reference: 'contactsCombo',
displayField: 'name',
name: 'contact',
typeAhead: false,
editable: false,
fieldLabel: 'Contact',
emptyText: 'Select a contact...',
anchor: '95%',
listeners: {
change: 'onSelectChange'
},
},
{
xtype: 'combo',
name: 'phone',
reference: 'phonesCombo',
fieldLabel: 'Phone',
displayField: 'number',
valueField:'id',
hiddenName: 'id',
emptyText: 'Select a phone...',
bind: {
store: '{contactsCombo.selection.phoneNumbers}'
},
anchor: '95%'
}
And corresponding models defines:
Ext.define('AppsBoard.model.Contact', {
extend: 'Ext.data.Model',
fields: [
'id', 'name'
],
});
Ext.define('AppsBoard.model.ViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.related',
stores: {
contacts: {
model: 'AppsBoard.model.Contact',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'contacts.json',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
}
});
Ext.define('AppsBoard.model.PhoneNumber', {
extend: 'Ext.data.Model',
fields: [
'id',
{
name: 'contact_id',
type: 'int',
reference: {
type: 'AppsBoard.model.Contact',
inverse: {
role: 'phoneNumbers'
}
}
},
'number'
],
proxy: {
type: 'MyProxy',
reader: {
type: 'json'
}
}
});
Ext.define('AppTest.store.MyProxy', {
extend: 'Ext.data.proxy.Proxy',
alias: 'proxy.MyProxy',
read: function (operation) {
var resultSet = {
1: [{
"id": 1,
"contact_id": 1,
"number": "6045551212"
},
{
"id": 2,
"contact_id": 1,
"number": "8009996541"
}],
2: [
{
"id": 3,
"contact_id": 2,
"number": "1232131233"
}
]
};
operation.setResultSet(this.getReader().read(resultSet[operation.getFilters()[0].getValue()]));
operation.setSuccessful(true);
},
erase: function (operation) {
console.log(operation);
}
});
My problem is when i switching my parent Combobox, it's associated child combobox shows valueField instead of displayField.
https://fiddle.sencha.com/#fiddle/vtg
you can see in your fiddle it's not use valueField but it's keep the value.
Since the store has been change the value is now not associated to anything in the new store, therefore you keep seen only the value.
you can clean the box by setting the forceSelection
{
xtype: 'combo',
name: 'phone',
reference: 'phonesCombo',
fieldLabel: 'Phone',
displayField: 'number',
valueField:'id',
hiddenName: 'id',
emptyText: 'Select a phone...',
forceSelection: true,
bind: {
store: '{contactsCombo.selection.phoneNumbers}'
},
anchor: '95%'
}
as long as you know there won't be a duplicates IDs

extjs treegrid displaying empty grid columns

I am trying to get a really basic tree grid working but all I get is an empty panel.
I copied the json string from a working treepanel example and added the date and filename myself for the extra grids.
So calling the bits root and children worked for a basic panel (i had it working when it only had the field text and was directly in the store. So i presumed it would work for a tree grid.
After searching I found that a treestore doesn't have a data config it had to be moved to the proxy. Now I just have empty date and filename columns.
so here is my model
Ext.define('Coda.common.repository.model.RepositoryMaintModel',{
extend: 'Ext.data.Model',
fields: [
{name: 'date', type: 'string'},
{name: 'filename', type: 'string'},
{name: 'text', type: 'string'},
{name: 'iconCls' , type: 'string', defaultValue: 'treenode-no-icon'},
{name: 'expanded' , type: 'boolean', defaultValue: true, persist: false},
{name: 'index' , type: 'int'}
]
});
and here is my view
Ext.define('view.RepositoryMaintView', {
extend: 'U4.panel.Panel',
requires: ['Ext.layout.container.HBox',
'model.RepositoryMaintModel',
'Ext.tree.Panel'],
EVENT_DOWNLOAD: 'download',
layout: 'hbox',
constructor: function (config) {
var me = this;
me.addEvents(
/**
* #event download
* #param {view.RepositoryMaintView} when pressing the download button
*/
me.EVENT_DOWNLOAD
);
var data = {root: {
expanded: true,
root: [
{ text: "detention",date:'10-01-2013', filename:'boo.txt', leaf: true },
{ text: "homework",date:'10-01-2013', filename:'boo.txt', expanded: true,
root: [
{ text: "book report",date:'10-01-2013', filename:'boo.txt', leaf: true },
{ text: "algebra",date:'10-01-2013', filename:'boo.txt', leaf: true}
] },
{ text: "buy lottery tickets",date:'10-01-2013', filename:'boo.txt', leaf: true }
]
}};
var store = Ext.create('Ext.data.TreeStore', {
model: 'blah.blah.model.RepositoryMaintModel',
// data: data, <-- remove from here
proxy: {
type: 'memory',
data: data, // <-- place here
reader: {
type: 'json',
root: 'root'
}
},
folderSort: true
});
var center = Ext.create('Ext.tree.Panel',{
title: 'Folders Companies Items',
//region: 'center',
width: 1000,
height: 200,
collapsible: false,
useArrows: true,
rootVisible: false,
store: store,
multiSelect: true,
columns: [
{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: 'hmm',
flex: 2,
sortable: true
},{
text: 'Date',
sortable: true,
dataIndex: 'date'
},{
text: 'filename',
sortable: true,
dataIndex: 'filename'
}]
});
me.items = [center];
me.callParent(arguments);
}
});

Extjs 4 Combobox data store can't show data

I am using Extjs 4.1, tried to load data for Combobox, but doesn't work. I have strong doubt about hte json reader root / record.
the data model and store are defined ,
Ext.define('tagModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'}
]
});
var tagStore = new Ext.data.Store({
model: 'tagModel',
proxy: {
type: 'ajax',
url: '/ExtjsWebApp/webresources/question/loadTags',
reader: {
type: 'json',
record : 'rtnList'
}
},
listeners: {
load: function(store, records, options){
alert("success " +records.length);
}
},
autoLoad: true
});
the ComboBox is defined as this,
{
itemId: 'search_tag_fld',
fieldLabel: 'Tag',
xtype: 'combobox',
displayField: 'name',
valueField: 'id',
store: tagStore,
queryMode: 'remote',
multiSelect: true,
anchor: '100%',
labelHeight: 300
}
I am sure that the restful webservice will return data as this
{"rtnList":[{"id":1,"name":"Java","active":"true"},{"id":2,"name":"J2EE","active":"true"},{"id":3,"name":"JMS","active":"true"},{"id":4,"name":"Design","active":"true"},{"id":5,"name":"SOA","active":"true"}],"successMsg":"success","errorMsg":"","time":"09/21/2013 18:34:55","sessionId":null,"userId":null}
In your reader, change "record" to "root". Here's a fiddle that shows that your current setup will work just fine: https://fiddle.sencha.com/#fiddle/km

How to Display the value of object in the combobox?

When I am trying to fetch data from the Store in the Combo Box,I am getiing output as--- [object Object]!!! but the value of the object is not coming!! Can any body tell me what is the problem or what should be the solution for this???
In Extjs 4.0:
Create data model
Ext.define('Bond', {
extend: 'Ext.data.Model',
idProperty: 'userid',
fields: [
{
name :'industryGroupsreName',
type:'string'
},
]
});
Create store
var industry=new Ext.data.Store(
{
model:'Bond',
proxy:
{
type: 'ajax',
url: 'industry.html',
reader: {
type: 'json'
}
}
});
industry.load();
Apply bellow code to your combo box
new Ext.create('Ext.form.ComboBox',
{
fieldLabel: 'Industry Group Name',
store: industry,
id: "industrygroup",
name: "industrygroup",
allowBlank: false,
hiddenName : 'industrygroup',
width:300,
queryMode: 'local',
displayField: 'industryGroupsreName',
valueField: 'industryGroupsreName'
}),

ExtJS4 grid won't update remote database

For some reason, this configuration of an ExtJS4 grid won't update. When you click on a cell, change a value, it hits the create URL, not the update URL, as defined in the proxy and observed with Firebug in FF4. Strangely, the datachanged event fires after loading the store when the page starts, but not after data has actually changed. Also, the grid send all rows to the create URL.
Can anyone tell me what I am doing wrong?
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = '/images/extjs4/s.gif';
Ext.tip.QuickTipManager.init();
//Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
Ext.define('VendorError', {
extend: 'Ext.data.Model',
fields: [
{name: 'UnexpSrvID', type: 'int'},
{name: 'VendorID', type: 'int'},
{name: 'VendorName', type: 'string'},
{name: 'VndActID', type: 'int'},
{name: 'VndActNb', type: 'string'},
{name: 'InvoiceID', type: 'int'},
{name: 'VInvNb', type: 'string'},
{name: 'VInvRcptDt', type: 'date', dateFormat: 'Y-m-d' },
{name: 'InvDate', type: 'date', dateFormat: 'Y-m-d' },
{name: 'CodeSpecifier', type: 'string'},
{name: 'Recurrence', type: 'string'},
{name: 'ClientID', type: 'int'},
{name: 'ClientName', type: 'string'},
{name: 'LocID', type: 'int'},
{name: 'LocName', type: 'string'},
{name: 'RecentLocStatus', type: 'string'},
{name: 'RecentLocStatusDate', type: 'date', dateFormat: 'Y-m-d' },
{name: 'UnexpCost', type: 'float'},
{name: 'ConfirmedAmt', type: 'float'},
{name: 'StaffID', type: 'int'},
{name: 'NetworkID', type: 'string'},
{name: 'UnexpStatCode', type: 'string'}
],
proxy: {
type: 'ajax',
simpleSortMode: true,
api: {
read: '/internal/viewVERext_json.asp',
create: '/internal/viewVERext_create.asp',
update: '/internal/viewVERext_update.asp',
destroy: '/internal/viewVERext_destroy.asp'
},
reader: {
type: 'json',
totalProperty: 'total',
successProperty: 'success',
messageProperty: 'message',
root: 'data'
},
writer: {
type: 'json',
writeAllFields: false,
allowSingle: false,
root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});
var store = Ext.create('Ext.data.Store', {
model: 'VendorError',
autoLoad: true,
autoSync: true,
pageSize: 20,
remoteSort: true,
listeners: {
// write: function(proxy, operation){
// if (operation.action == 'destroy') {
// main.child('#form').setActiveRecord(null);
// }
// Ext.example.msg(operation.action, operation.resultSet.message);
// }
datachanged: function() {
var report = "";
store.each(
function(rec) {
report = report + rec.dirty + '/';
}
)
alert(report);
}
}
});
// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
//stateful: true,
//stateId: 'stateGrid',
columns: [
{ text : 'Vendor',
dataIndex: 'VendorName',
flex : 1
},
{ text : 'Account',
dataIndex: 'VndActNb'
},
{ text : 'Invoice',
dataIndex: 'VInvNb'
},
{ text : 'Invoiced',
dataIndex: 'InvDate',
xtype : 'datecolumn',
align : 'center'
},
{ text : 'Receipted',
dataIndex: 'VInvRcptDt',
xtype : 'datecolumn',
align : 'center'
},
{ text : 'Description',
dataIndex: 'CodeSpecifier'
},
{ text : 'Client',
dataIndex: 'ClientName'
},
{ text : 'Location',
dataIndex: 'LocName'
},
{ text : 'LStatus',
dataIndex: 'RecentLocStatus',
align : 'center'
},
{ text : 'Credit',
dataIndex: 'UnexpCost',
tdCls : 'colyellow',
renderer : Ext.util.Format.usMoney,
align : 'right',
field : { xtype:'textfield', allowBlank:false }
},
{ text : 'Confirmed',
dataIndex: 'ConfirmedAmt',
tdCls : 'colyellow',
renderer : Ext.util.Format.usMoney,
align : 'right',
field : { xtype:'textfield', allowBlank:false }
},
{ text : 'Recurrence',
dataIndex: 'Recurrence',
tdCls : 'colyellow',
align : 'center',
field : {
xtype : 'combobox',
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: [
['once','once'],['1st','1st'],['2nd+','2nd+']
],
lazyRender: true
}
},
{ text : 'CStatus',
dataIndex: 'UnexpStatCode',
tdCls : 'colyellow',
align : 'center',
field : {
xtype : 'combobox',
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: [
<%=cstat_grid%>
],
lazyRender: true
}
},
{ text : 'Owner',
dataIndex: 'NetworkID',
tdCls : 'colyellow',
field : {
xtype : 'combobox',
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: [
<%=staff_grid%>
],
lazyRender: true
}
}
],
layout: 'fit',
height: 500,
renderTo: 'theGrid',
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
dockedItems: [
{ xtype: 'pagingtoolbar',
store: store,
dock: 'bottom',
displayInfo: true
},
{ xtype: 'toolbar',
dock: 'top',
items: [
{ xtype:'button',
text: 'IsDirty()',
handler: function() {
var report = "";
store.each(
function(rec) {
report = report + rec.dirty + '/';
}
)
alert(report);
}
}
]
}
],
viewConfig: {
stripeRows: true
}
});
Ext.EventManager.onWindowResize(grid.doLayout, grid);
});
Turns out the issue is that records added into the grid are detected as "not new" by the value of a unique id field. A kind poster on the Sencha forums pointed me to this.
By default, this field in the model is expected to have a name of 'id'. So, you must either provide a model with a field of 'id', which my model above did not have, or you must override the default column by using the idProperty property of Ext.data.Model. I simply renamed the UnexpSrvId column to id. And, lo and behold, we send updates to update() instead of create().
This is not obvious from the API docs, as many things unfortunately are in this powerful framework.
Because your grid is using the CellEdit mixin you can add a listener to the grid which will commit the changes to your record after editing. So in your grid, add the listeners config option defined as follows...
listeners: {
edit : function(e) {
e.record.commit();
}
}
EDIT: I think you're using the wrong syntax on your proxy... you can only define a reader and writer (by the looks of things)...
Ed Spencer's article on Proxies
ExtJS 4 API Entry on Proxies

Resources