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
Related
I'm unsuccessful in getting binding associations working in the admin dashboard template (with the desired behavior of selecting a record from a combobox and pulling up associated records in a grid).
My main viewModel is defined as:
Ext.define('Admin.view.main.MainModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.main',
stores: {
patients: {
model: 'md_registry.model.Patient',
autoLoad: true
}
}
});
I added a leaf node to Pages in NavigationTree.js:
{
text: 'Pages',
iconCls: 'x-fa fa-leanpub',
expanded: false,
selectable: false,
//routeId: 'pages-parent',
//id: 'pages-parent',
children: [
{
text: 'Proc',
iconCls: 'x-fa fa-send',
rowCls: 'nav-tree-badge nav-tree-badge-hot',
viewType: 'procedure',
leaf: true
}]
}
With the procedure view being:
Ext.define('Admin.view.pages.Procedure', {
extend: 'Ext.panel.Panel',
xtype: 'procedure',
requires: [
'Ext.panel.Panel',
'Admin.model.Patient',
'Admin.model.Procedure'
//'Admin.model.Diagnosis'
],
anchor : '100% -1',
referenceHolder: true,
width: 1000,
height: 1000,
referenceHolder: true,
layout: {
type: 'hbox',
align: 'stretch'
},
viewModel: 'main',
session: {},
items: [
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
{
xtype: 'fieldset',
layout: 'anchor',
items: [{
xtype: 'combobox',
listeners : {
select : function() {
console.log(arguments)
console.log(arguments[1].data.birth_date)
console.log(arguments[1].data.first_name)
console.log(arguments[1].data.last_name)
console.log(arguments[1].data.sex)
}
},
bind: {
store: '{patients}'
},
reference: 'patientCombo',
publishes: 'id',
fieldLabel: 'Patient Search',
displayField: 'mrn',
//anchor: '-',
// We're forcing the query to run every time by setting minChars to 0
// (default is 4)
minChars: 2,
queryParam: '0',
queryMode: 'local',
typeAhead: true,
// https://www.sencha.com/forum/showthread.php?156505-Local-combobox-with-any-match-filter
doQuery: function(queryString, forceAll) {
this.expand();
this.store.clearFilter(!forceAll);
if (!forceAll) {
this.store.filter(this.displayField, new RegExp(Ext.String.escapeRegex(queryString), 'i'));
}
}
}, {
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
xtype: 'displayfield',
fieldLabel: 'Selected Patient',
bind: {
html: '<p>Name: <b>{patientCombo.selection.first_name}, ' +
'{patientCombo.selection.last_name} </b></p>' +
'<p>Sex: {patientCombo.selection.sex}</p>' +
'<p>Birthdate: {patientCombo.selection.birth_date}</p>'
}
}]
},
{
title: 'Procedures',
xtype: 'grid',
bind: '{patientCombo.selection.procedures}',
flex: 1,
margin: '0 0 0 10',
columns: [{
text: 'Procedure Date', dataIndex: 'proc_date', flex: 1
}, {
text: 'Procedure', dataIndex: 'proc_name', flex: 1
}],
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : new Ext.XTemplate(
'<p><b>Proc Name Orig:</b> {proc_name_orig}</p>',
'<p><b>Proc Code:</b> {proc_code}</p>',
'<p><b>Proc Code Type:</b> {proc_code_type}</p>')
}],
viewConfig: {
emptyText: 'No procedures',
deferEmptyText: false
}
}]
});
My Patient and Procedure models are simply:
Ext.define('Admin.model.Procedure', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
//{ name: 'id', type: 'string' },
{ name: 'proc_code', type: 'string' },
{ name: 'proc_name', type: 'string' },
{ name: 'proc_code_type', type: 'string' },
{ name: 'proc_name_orig', type: 'string' },
{ name: 'proc_date', type: 'date', format: 'Y-m-d' },
{
name: 'patient_id',
type: 'string',
reference: {
parent: 'Admin.model.Patient',
//type: 'md_registry.model.Patient',
inverse: 'procedures',
autoLoad: false
}
}
],
proxy: {
type: 'rest',
url: 'http://127.0.0.1:5000/procedureview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
and
Ext.define('Admin.model.Patient', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.proxy.Rest'
],
fields: [
{ name: 'id', type: 'string' },
{ name: 'mrn', type: 'string' },
{ name: 'birth_date', type: 'date', format: 'Y-m-d' },
{ name: 'sex', type: 'string' },
{ name: 'first_name', type: 'string' },
{ name: 'last_name', type: 'string' }
],
proxy: {
type: 'ajax',
url: 'http://127.0.0.1:5000/patientview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
respectively.
The data for my Patients store are getting loaded into the combobox just fine, but when I select an item from the combo list it is not firing off the call to grab the associated procedures data (see image: .
However, the binding associations work as expected with Side Navigation Tabs (see image: , and show up within the object prototype chain, as expected... see
(whereas for the admin dashboard, the associations are empty).
I cannot for the life of me get these working in the Admin Dashboard. I noticed a tool called the bind inspector, but I am running the GPL version of the SDK, so I do not have access to this. Beyond this, I cannot figure out a way to debug why the binding association is not working in the admin dashboard, but otherwise works perfectly well in Side Navigation Tabs.
I would set up a Fiddle, but I have no idea how to do it using the Admin Template.
I just figured it out. It was a namespace issue.
My reference in the procedure model should be:
reference: {
parent: 'Patient',
inverse: 'procedures',
autoLoad: false
}
Voila, all the associated data get loaded as expected!
I'm using ExtJS 6.0.1 and want to drag items from a grid over a tree so I can change some category values into the grid records.
But on drop event I get this error: "TypeError: path is undefined". The error is returned by the function ensureVisible from Ext.tree Panel class, first line.
var foldersStore = Ext.create("Ext.data.TreeStore",{
storeId: 'foldersTreeStore',
proxy: {
type: 'ajax',
url: 'categories/tree.json'
},
autoLoad: true
});
var foldersTree = Ext.create("Ext.tree.Panel",{
title: 'Categories',
hideHeaders: true,
renderTo: 'folders-tree',
rootVisible: false,
allowDeselect: true,
store: foldersStore,
droppedRecords: undefined,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
dragText: 'Drag and drop to reorganize',
dropGroup: 'bkmDDGroup',
appendOnly: true
},
listeners: {
beforedrop: function(node, data, overModel, dropPos, opts) {
this.droppedRecords = data.records;
data.records = [];
console.log(this.droppedRecords);
},
drop: function(node, data, overModel, dropPos, opts) {
console.log(arguments);
}
}
}
});
var filesStore = Ext.create("Ext.data.Store",{
storeId:'filesTableStore',
fields:[
{name: 'eid', type:'string'},
{name: 'fileName', type:'string'},
{name: 'createdAt', type:'string'},
{name: 'mimeType', type:'string'},
{name: 'version', type:'string'},
{name: 'size', type:'int'},
{name: 'creator', type:'string'},
{name: 'modifier', type:'string'},
{name: 'status', type:'string'},
{name: 'tmpId'}
],
proxy: {
type: 'ajax',
url: 'documents/list.json',
reader: {
type: 'json',
rootProperty: "list"
}
},
autoLoad: true
});
var filesTable = Ext.create("Ext.grid.Panel",{
store: filesStore,
title:'Files',
selModel: {
mode: "MULTI",
allowDeselect: true
},
columns:[
{
text:'File Name',
flex:1,
dataIndex:'fileName'
},{
text:'Created By',
flex:1,
dataIndex:'creator'
},{
text:'Mime Type',
width: 150,
dataIndex:'mimeType'
},{
text:'Size',
width: 100,
dataIndex:'size'
},{
text:'Version',
width: 80,
dataIndex: 'version'
},{
text:'Status',
width: 100,
dataIndex:'status'
},{
text:'Created At',
width:150,
dataIndex:'createdAt'
}],
renderTo:'files-table',
height:UI.getContentHeight("#files-table"),
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragText: 'Drag and drop to reorganize',
dragGroup: 'bkmDDGroup'
}
}
});
From my point of view looks like I've forgot some config, still don't have any idea yet. Even if I have a single console.log line in drop event, the error remains the same.
Any clues will be much appreciated.
Thanks
In the beforedrop listener you are deleting the records you've selected:
data.records = []
Instead you must prepare that records to drop into TreePanel where data model differs from the grid.
Link to the realization
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);
}
});
Treegrid is not getting rendered properly. Here is the code:
treeGrid.js :
Ext.define('App.view.DBStatusGrid', {
extend : 'Ext.container.Container',
xtype : 'app-DB-grid',
layout : 'vbox',
items : [
{
xtype : 'container',
cls : 'boxTitle',
html : 'DB Details'
},
{
xtype : 'treepanel',
singleExpand: true,
useArrows:true,
rootVisible:false,
columns: [
{text: 'Server Status', dataIndex: 'serverStatus' , width: 80,},
{ xtype: 'treecolumn',text: 'Server Name', dataIndex: 'serverName' , width: 140},
{ text: 'Instance Status', align:'center', dataIndex: 'instanceStatus',width: 80,},
{text: 'Instance Name', align:'center', dataIndex: 'instanceName',width: 140}
]
}
]
});
property.json :
"data":[
{
"serverStatus": "active",
"serverName":"rg0C1",
"iconCls":"task-folder",
"expanded":false,
"data": [
{
"instanceStatus": "active",
"instanceName":"OA1",
"leaf":true,
"iconCls":"no-icon"
}
]
}
]
Creating store
Ext.define('App.view.InnerContainerView', {
extend : 'Ext.container.Container',
xtype : 'app-inner-ContainerView',
config : {
component : 'NONE',
parentView : ''
},
initComponent : function() {
var parentView = this.getParentView();
this.items = [
{
xtype : 'container',
layout: 'card',
items : [
{
xtype: 'app-DB-grid',
parentView: parentView,
listeners :{
render : function(){
var store = Ext.create('Ext.data.TreeStore',
{
model: 'App.model.treeModel',
autoLoad: true,
proxy: {
type: 'ajax',
url:'app/data/property.json',
reader: {
type: 'json',
root : 'data'
}
},
root :{
expanded :true
}
});
this.down('treepanel').setRootNode(store.getRootNode()); // I am getting my treegrid,and setting the rootnode.
}
]
}
]
this.callParent();
});
My Problem :
From the json property file,only serverName is getting displayed in the treegrid.When I try to expand the serverName,it is not getting expanded.Please help me resolve this issue.Please point me to the correct direction if I am going wrong somewhere.Any help would be appreciated.Thanks.
What about having the store available before the component is created?
Ext.widget({
renderTo: Ext.getBody(),
xtype : 'treepanel',
singleExpand: true,
useArrows:true,
rootVisible:false,
columns: [
{text: 'Server Status', dataIndex: 'serverStatus' , width: 80,},
{xtype: 'treecolumn',text: 'Server Name', dataIndex: 'serverName' , width: 140},
{text: 'Instance Status', align:'center', dataIndex: 'instanceStatus',width: 80,},
{text: 'Instance Name', align:'center', dataIndex: 'instanceName',width: 140}
]
,store: Ext.create('Ext.data.TreeStore', {
model: 'App.model.treeModel',
autoLoad: true,
proxy: {
type: 'ajax',
url:'property.json',
reader: {
type: 'json',
root : 'data'
}
},
root :{
expanded :true
}
})
});
I assumed from the presence of the xtype that you didn't define a class for that component, but that could also be done:
Ext.define('My.TreePanel', {
extend: 'Ext.tree.Panel',
singleExpand: true,
useArrows:true,
rootVisible:false,
columns: [
{text: 'Server Status', dataIndex: 'serverStatus' , width: 80,},
{xtype: 'treecolumn',text: 'Server Name', dataIndex: 'serverName' , width: 140},
{text: 'Instance Status', align:'center', dataIndex: 'instanceStatus',width: 80,},
{text: 'Instance Name', align:'center', dataIndex: 'instanceName',width: 140}
]
// Providing only configuration (as opposed to a store instance) in order for
// each tree to have its own store instance
,store: {
model: 'App.model.treeModel',
autoLoad: true,
proxy: {
type: 'ajax',
url:'property.json',
reader: {
type: 'json',
root : 'data'
}
},
root :{
expanded :true
}
}
});
Ext.create('My.TreePanel', {
renderTo: Ext.getBody()
});
Or this way, that would allow us to be more dynamic with the store creation:
Ext.define('My.TreePanel', {
extend: 'Ext.tree.Panel',
singleExpand: true,
useArrows:true,
rootVisible:false,
columns: [
{text: 'Server Status', dataIndex: 'serverStatus' , width: 80,},
{xtype: 'treecolumn',text: 'Server Name', dataIndex: 'serverName' , width: 140},
{text: 'Instance Status', align:'center', dataIndex: 'instanceStatus',width: 80,},
{text: 'Instance Name', align:'center', dataIndex: 'instanceName',width: 140}
]
,initComponent: function() {
// Creating store instance myself at creation time
this.store = Ext.create('Ext.data.TreeStore', {
model: 'App.model.treeModel',
autoLoad: true,
proxy: {
type: 'ajax',
url:'property.json',
reader: {
type: 'json',
root : 'data'
}
},
root :{
expanded :true
}
});
// Don't forget to call the superclass method!
this.callParent(arguments);
}
});
Ext.create('My.TreePanel', {
renderTo: Ext.getBody()
});
![ I am using extjs 4 . and using RowEditing plug, added multi selection combo box , The combo box is showing the keys instead of the values , But when I select any row it is showing the values , After that when I do some changes to the data in any gievn row, Then the values start showing .
Also I could not see the checkbox when the row is not selected and showing the checkbox when it is selected .
Code
Model is :
Ext.define('Employee', {
extend: 'Ext.data.Model',
idProperty:'employeeId',
fields: [
{name: 'alertType', type: 'string'},
{name: 'statusCode', type: 'bool'},
{name: 'employeeId', type: 'string'},
{name: 'employeeName', type: 'string'},
{name: 'jobCode', type: 'string'},
{name: 'jobTitle', type: 'string'},
{name: 'jobTarget', type: 'string'},
{name: 'vpPlan', type: 'string'},
{name: 'losPlanName', type: 'string', convert:function(v, record){if(typeof v =="string") return v.split(","); else return v; }},
{name: 'losPlanCodes', type: 'float[]', convert:function(v, record){if(typeof v =="string") return v.split(","); else return v; }},
{name: 'losLocation', type: 'string', convert:function(v, record){if(typeof v =="string") return v.split(","); else return v; }},
{name: 'losLocationCodes', type: 'float[]', convert:function(v, record){if(typeof v =="string") return v.split(","); else return v; }},
{name: 'entity', type: 'string'},
{name: 'locationCode', type: 'string'},
{name: 'deptId', type: 'string'},
{name: 'deptName', type: 'string'},
]
});
Grid Store :-
var directReportiesStore = Ext.create('Ext.data.Store', {
autoDestroy: true,
autoLoad:true,
autoSync: true,
allowSingle: true,
storeId: 'directReportiesStore',
model: 'Employee',
sorters: [{
property: 'employeeName',
direction:'ASC'
}],
proxy: {
type: 'ajax',
url: 'getDirectReportiesJson.do?plannerId='+plannerId,
api: {
update: 'getDirectReportiesJson.do?plannerId='+plannerId,
},
reader: {
type: 'json',
successProperty: 'success',
idProperty: 'employeeId',
root: 'data',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: false
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
write: function(proxy, operation){
Ext.example.msg(operation.action, operation.resultSet.message);
}
},
listeners: {
load: function(store,records){
for(var rec=0; rec< records.length; rec++){
for(var i=0; i< Ext.getCmp('employeeGrid').columns.length; i++){
if(Ext.getCmp('employeeGrid').columns[i].getId() =='losLocationCodes'){
alert(Ext.getCmp('employeeGrid').columns[i].getId())
Ext.getCmp('employeeGrid').columns[i].getEditor().setValue(records[rec].get('losLocationCodes'))
alert(records[rec].get('losLocationCodes'));
}
}
}
}
}
});
![][1]
Combo Box stores :
// create the Plan Store
var planStore = Ext.create('Ext.data.Store', {
autoDestroy: true,
storeId: 'planStore',
idIndex: 0,
fields: [
{name: 'planId', type: 'float'},
{name: 'planName', type: 'string'},
{name: 'planTypeName', type: 'string'},
]
});
planStore.loadData(plansJson);
// create the Location Store
var locationStore = Ext.create('Ext.data.Store', {
autoDestroy: true,
storeId: 'locationStore',
idIndex: 0,
fields: [
{name: 'locAreaId', type: 'float'},
{name: 'locAreaName', type: 'string'},
{name: 'active', type: 'string'},
{name: 'inclRegAvg', type: 'string'},
]
});
locationStore.loadData(locationJson);
GRID using all three stores ...
var grid = Ext.create('Ext.grid.Panel', {
store: directReportiesStore,
id:'employeeGrid',
title: 'Employee Varieable Pay Mapping',
width: 1100,
height: 400,
frame: true,
columns: [{
id: 'alertType',
header: 'Alert',
width: 30,
dataIndex: 'alertType',
editor: {
disabled: true
}
} , {
id: 'statusCode',
header: 'Reviewed?',
dataIndex: 'statusCode',
width: 40,
editor: {
xtype: 'checkbox',
cls: 'x-grid-checkheader-editor'
}
} , {
id: 'employeeId',
header: 'Employee Id',
dataIndex: 'employeeId',
width: 50,
editor: {
disabled: true
}
} ,{
id: 'employeeName',
header: 'Employee Name',
dataIndex: 'employeeName',
flex: 1,
editor: {
disabled: true
}
} ,{
id: 'jobCode',
header: 'Job Code',
dataIndex: 'jobCode',
width: 40,
editor: {
disabled: true
}
} ,{
id: 'jobTitle',
header: 'Job Title',
dataIndex: 'jobTitle',
flex: 1,
editor: {
disabled: true
}
} ,{
id: 'jobTarget',
header: 'Job Target',
dataIndex: 'jobTarget',
width: 40,
editor: {
disabled: true
}
} , {
id:'vpPlan',
header: 'VP Plan',
dataIndex: 'vpPlan',
width: 70,
editor: {
xtype: 'combobox',
typeAhead: true,
editable: false,
triggerAction: 'all',
selectOnTab: true,
store: [
['SCAL','SCAL'],
['Shared Svc','Shared Svc'],
],
lazyRender: true,
listClass: 'x-combo-list-small'
}
}, {
id:'losPlanCodes',
header: 'LOS Plan Name',
dataIndex: 'losPlanCodes',
width: 250,
editor: {
xtype: 'combobox',
typeAhead: true,
triggerAction: 'all',
tooltip: 'losPlanName',
selectOnTab: true,
store: planStore,
queryMode: 'local',
lazyRender: true,
multiSelect: true,
displayField: 'planName',
valueField:'planId'
}
}, {
id:'losLocationCodes',
header: 'LOS Location',
dataIndex: 'losLocationCodes',
width: 90,
editor: {
xtype: 'combobox',
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
autoSelect: true,
store: locationStore,
queryMode: 'local',
multiSelect: true,
lazyRender: true,
valueField:'locAreaId',
displayField: 'locAreaName',
listClass: 'x-combo-list-small'
//value: 'losLocationCodes',
//data : 'losLocationCodes',
/*
listeners : {
'beforeselect' : function(combo, record,index){
},
'change': function(combo, newValue, oldValue){
},
'afterrender': function(combo, record1) {
}
}
*/
}
},{
id: 'Entity',
header: 'entity',
dataIndex: 'entity',
width: 30,
editor: {
disabled: true
}
} , {
id: 'locationCode',
header: 'Location Code',
dataIndex: 'locationCode',
width: 50,
editor: {
disabled: true
}
} ,{
id: 'deptId',
header: 'Dept Code',
dataIndex: 'deptId',
width: 50,
editor: {
disabled: true
}
} ,{
id: 'deptName',
header: 'Dept Name',
dataIndex: 'deptName',
flex: 1,
editor: {
disabled: true
}
}],
selModel: {
selType: 'cellmodel'
//selType: 'checkboxmodel'
},
renderTo: 'editor-grid',
tbar: [{
text: 'Select All'
}],
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
pluginId: 'employeeEditing',
autoCancel: false,
listeners: {
'beforeedit': function(editor, e, eOpts) {
// alert(editor.rowIdx)
// alert(editor.field)
// alert(editor.value)
if (editor.record.get('entity') == 2 || editor.record.get('entity') == 02){
grid.getPlugin('employeeEditing').editor.form.findField('losPlanCodes').disable();
grid.getPlugin('employeeEditing').editor.form.findField('losLocationCodes').disable();
} else if (editor.record.get('entity') == 8 || editor.record.get('entity') == 08){
grid.getPlugin('employeeEditing').editor.form.findField('losPlanCodes').disable();
}
/*
var me = this;
this.isEditAllowed = false;
this.cancelEdit();
Ext.MessageBox.show({
title: 'Not Allowed to Edit',
msg: 'Not Allowed to Edit this record with entity'+ this.entity,
icon: Ext.MessageBox.INFO,
buttons: Ext.Msg.OK
});
return true;
*/
},
'cancelEdit': function(editor) {
grid.getPlugin('employeeEditing').editor.form.findField('losPlanCodes').enable();
grid.getPlugin('employeeEditing').editor.form.findField('losLocationCodes').enable();
},
'validateedit': function(e) {
},
'edit': function(editor) {
if (editor.record.get('entity') == 2 || editor.record.get('entity') == 02){
grid.getPlugin('employeeEditing').editor.form.findField('losPlanCodes').enable();
grid.getPlugin('employeeEditing').editor.form.findField('losLocationCodes').enable();
}
else if (editor.record.get('entity') == 8 || editor.record.get('entity') == 08){
grid.getPlugin('employeeEditing').editor.form.findField('losPlanCodes').enable();
}
}
}
})
],
listeners: {
'render': function(grid) {
}
}
});
grid.getSelectionModel().on('selectionchange', this.onSelectChange, this);
Please help
][1]
Most likely you are setting the value of the combobox BEFORE its data is loaded. Review the order of the events, try to use a callback for when the store has loaded, and setting its value after that.
You probably figured this out by now, but in case not, you need a custom renderer on the column config to pluck the displayfield out, i.e:
{
id:'losPlanCodes',
header: 'LOS Plan Name',
dataIndex: 'losPlanCodes',
width: 250,
editor: {
xtype: 'combobox',
typeAhead: true,
triggerAction: 'all',
tooltip: 'losPlanName',
selectOnTab: true,
store: planStore,
queryMode: 'local',
lazyRender: true,
multiSelect: true,
displayField: 'planName',
valueField:'planId'
},
renderer: function(value, metaData, record, row, col, store, view) {
return planStore.getById(value).get('planName');
}
},