Extjs Comobobox duplicate display field not allowed to be set? - extjs

I'm a newbie using Extjs 4.07. I have created a combobox (remote) queryMode. The combobox displays a list of courses. However, the institution I work for recently recoded their entire courses. So, I end up having two records with the same display field. My JSON looks like this:
{"result":[{"id":"90223","code":"CM12","description":"Introduction to C Programming","creditHours":"3.00","numberOfLabs":"0","contactHours":null,"chargeableCredits":null},
{"id":"2094","code":"CMPS1302","description":"Introduction to C Programming","creditHours":"3.00","numberOfLabs":"0","contactHours":null,"chargeableCredits":null}],"total":2}
the display field is description and the value field is id. When I select one of the items in the combobox and submit everything works fine. The problem occurs if later I selected the incorrect course and select the other one.
I have tried setting the idProperty: 'id' but to no avail. When I submit the form the value that will be sent is the one that was selected first after. Note: This only happens for duplicate course descriptions, everything else works fine.
here is some code to help explain the problem:
Ext.define('SIS.model.ManageCourse', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'code', type: 'string'},
{name: 'description', type: 'string'},
{name: 'creditHours', type: 'float'},
{name: 'contactHours', type: 'float'},
{name: 'chargeableCredits', type: 'float'},
{name: 'numberOfLabs', type: 'float'},
{name: 'selected', type: 'bool'} //for update course pre-requisites
]
});
Ext.define('SIS.store.ClassCourse', {
extend: 'Ext.data.Store',
autoLoad: true,
autoSync: true,
model: 'SIS.model.ManageCourse',
pageSize: 7,
remoteFilter: true,
idProperty: 'id',
proxy: {
type: 'ajax',
api: {
read: 'course/select'
},
reader : {
type : 'json',
root : 'result',
totalProperty : 'total',
successProperty : 'success'
}
}
});
Ext.define('SIS.view.class.ClassCourseCombo', {
extend: 'Ext.form.ComboBox',
alias: 'widget.ClassCourseCombo',
name: 'courseId',
fieldLabel: 'Course',
store: 'ClassCourse',
queryMode: 'remote',
pageSize: 7,
displayField: 'description',
valueField: 'id',
allowBlank: false,
hideTrigger: true,
forceSelection: true,
minChars: 1,
lazyInit: false,
listConfig: {
getInnerTpl: function () {
return '<div class="combo-header">{description}</div>\
<div class="combo-item">{code}</div>';
}
}
});

Having same display value for different rows in combo box is confusing at least for the end user. Why don't you create a calculated field like this:
fields: [
{ name: 'id', type: 'int' },
{ name: 'description', type: 'string' },
{ name: 'display', type: 'string', convert: function(v, r) {
return r.get('id') + ' ' + r.get('description');
}}
}]
And use this display as your displayField.

This is a bug identified since version 3 I found the solution in sencha forum provided by Condor.
I changed the line
if(val.length > 0 && val != this.emptyText)
with
if(val.length > 0 && val != this.emptyText && typeof this.emptyText != 'undefined')
when there is no emptyText defined the result is just as if forceSelection was set to false even when explicitly set to true. small fix.

Related

Extjs treepicker error when reading from a json format

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 .

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

Where's my EXT JS 4 model data?

Using Ext JS 4.1....
I have a grid that displays a bunch of Model instances, although only some of the fields are displayed. I then have a double-click listener where I would like to load the entire record into a form for editing. In the double-click listener I do not see the data in my hasMany association although the json data is being returned according to Firebug's Net display where I see the response from the server call. Is there something wrong with my model or am I going about this wrong?
Request.js
Ext.define('Request', {
extend: 'Ext.data.Model',
requires: ['PointOfContact'],
fields: [
{name: 'id', type: 'int'},
{name: 'project', type: 'string'},
{name: 'purpose', type: 'string'},
{name: 'status'},
{name: 'additionalInfo', type: 'string'}
],
hasMany: [{
model: 'PointOfContact',
name: 'pointOfContacts',
foreignKey: 'id',
associationKey: 'pointOfContacts'
}],
proxy: {
type: 'rest',
url: '/web/project/rest/request/',
reader: { type: 'json' },
writer: { type: 'json' }
}
});
PointOfContact.js
Ext.define('PointOfContact', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'fullName', type: 'string'},
{name: 'email', type: 'string'},
{name: 'phone', type: 'string'}
]
});
Requests.js
Ext.define('Requests', {
extend: 'Ext.data.Store',
model: 'Request',
autoLoad: true
});
RequestsView.js
Ext.define('RequestsView', {
extend: 'Ext.grid.Panel',
title: 'All Requests',
store: 'Requests',
viewConfig: {
singleSelect: 'true',
listeners: {
itemdblclick: function(dataview, record, item, index, e) {
console.log(record.get('project'));
console.log(record.get('purpose'));
console.log(record.get('status'));
console.log(record.get('additionalInfo'));
console.log(record.get('pointOfContacts'));
var comp = Ext.ComponentQuery.query('requestForm');
comp[0].getForm().loadRecord(record);
var mainPanel = Ext.ComponentQuery.query('mainpanel');
mainPanel[0].getLayout().setActiveItem('requestForm');
}
}
},
columns: [
{header: 'Project', dataIndex: 'project', flex: 1},
{header: 'Purpose', dataIndex: 'purpose', flex: 1},
{header: 'Status', dataIndex: 'status', flex: 1}
]
});
So in the console I see the values for project, purpose, status and additionalInfo but I get "undefined" for pointOfContacts.
Any suggestions?
UPDATE WITH FINAL WORKING CODE:
Here is the working code I used to retrieve the pointofContacts and load a grid on my form panel with the pointOfContacts
...
itemdblclick: function(dataview, record, item, e) {
var comp = Ext.ComponentQuery.query('requestForm');
comp[0].getForm().loadRecord(record);
Ext.getCmp('pocGrid').reconfigure(record.pointOfContacts());
var mainPanel = Ext.ComponentQuery.query('mainpanel');
mainPanel[0].getLayout().setActiveItem('requestForm');
}
....
Has many associations are not parsed in to associated records by default. Especially for the grid - as that is supposed to be a flat data view. Model docs show you how to setup associations but don't say anything about creating instances for you :)
There are links to usage of has many (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.association.HasMany) from the Model docs. Unfortunately the usage is not what you expect it to be. Essentially it is designed to fetch the records on demand by calling their store to load.

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 itemId, how to get back a combobox column editor

I am trying to convert some ExtJS 3.3 to 4.0.
In ExtJS 3.x I could create a combobox with a unique component Id, that I could use later with Ext.getCmp(Id), to get that combo editor, so that I could add filters, or play with the combo box itself.
Now if I specify an Id, the grid does not render the combo box correct in the grid, they say I have to use itemId instead, then actually it works, I mean combo renders correctly on the grid, But then I have no way of using that itemId to get the combobox itself.
I tried grid.getComponent(itemId), grid.headerCt.getComponent(), I have to say what the heck is this itemId good for, how on earth am I supposed to get this editor.
grid.columns collection has editor for simple fields (like text, number), for combobox it has getEditor which asks for a data record as a param.
I have to say again wtf, was so wrong with ExtJS 3.x that they felt like fixing and f.... it up.
Really, this upgrade made me go wtf so many times.... maybe its my fault, but wtf... anyways.
{
header: 'Ürün/Hizmet',
width: 90,
dataIndex: 'AlinanHizmetId',
editor: {
itemId: 'AlinanHizmetId',
xtype: 'combobox',
allowBlank: false,
selectOnFocus: true,
valueField: 'Id',
displayField: 'HizmetAd',
triggerAction: 'all',
typeAhead: false,
forceSelection: true,
lazyRender: true,
minChars: '2',
listWidth: 300,
store: Ext.create('Ext.data.Store', {
storeId: '',
fields: [{
name: 'HizmetTipAd',
caption: 'Hizmet Tip Adı',
type: Ext.data.Types.STRING,
clrType: 'String'
}, {
name: 'Id',
caption: 'Id',
type: Ext.data.Types.STRING,
clrType: 'Guid'
}, {
name: 'HizmetTip',
caption: 'HizmetTip',
type: Ext.data.Types.STRING,
clrType: 'String'
}, {
name: 'HizmetKod',
caption: 'Hizmet Kodu',
type: Ext.data.Types.STRING,
clrType: 'String'
}, {
name: 'HizmetAd',
caption: 'Hizmet Adı',
type: Ext.data.Types.STRING,
clrType: 'String'
}, {
name: 'Aciklama',
caption: 'Açıklama',
type: Ext.data.Types.STRING,
clrType: 'String'
}],
autoDestroy: false,
autoLoad: true,
autoSave: false,
sortInfo: {
field: 'HizmetAd',
direction: 'ASC'
},
restful: false,
proxy: {
type: 'ajax',
actionMethods: {
read: 'POST'
},
url: '/Yol/Combo/AlinanHizmet',
reader: {
type: 'json',
root: 'data',
idProperty: 'Id',
totalProperty: 'rowCount',
successProperty: 'success',
messageProperty: 'message'
}
},
data: []
})
},
filter: {
xtype: 'textfield'
},
renderer: function (value, metaData, record, rowIndex, colIndex, store) {
return record.get('HizmetAd');
}
}
This is old - but have you tried grid.down('#item_id')?
mygrid.on('beforeedit', function(e){
if(e.field == 'ProductId') {
var gridCols = Ext.getCmp('my_grid').columns;
for(i = 0; i < gridCols.length; i++)
if (gridCols[i].dataIndex == 'ProductId') break;
var combo = gridCols[i].getEditor(e.record);
...
so actually column.getEditor(null) does the trick.

Resources