PDA

View Full Version : RowEditing with Combobox - changes shown "id", should be displayed "displayField"



Lexxx_HU
24 Jul 2014, 12:25 AM
Hi)
RowEditing with Combobox - changes (click row editing) shown "id"
should be displayed "displayField"


49748



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]
});

kcarpenter528
25 Jul 2014, 4:16 AM
I had this problem as well.
I ended up setting the column.dataIndex, comobobox.dispalyField and combobox.valueField to the field that should be shown - in my case 'name'.
Then I used the Select event of the combobox to update the field. Select provides the full record in its arguments, so you can still get the ID from it.

Also, you'll probably have better luck if you post this in the discussion thread of the specific EXTJS version you are using.

Lexxx_HU
25 Jul 2014, 7:10 AM
I found the solution

Ext.define('ModelLib', {
extend: 'Ext.data.Model',
fields: [
{name: 'trID', type: 'int'},
{name: 'trName', type: 'string'}
]
});
need to specify the type of field