Related
I requires Ext.grid.plugin.Editable in my grid. Now I want to change classes inside default panel, witch slides right for editing of row.
But I don't understand how I to manage submit and delete button function (for example I want to define POST for submit button).
toolbarConfig - doesn't work
Ext.define('Foresto.model.EditListRenters', {
extend: 'Ext.grid.Grid',
xtype: 'rentlist',
requires: [ //some plugins and models
],
frame: true,
store: {
model: 'Foresto.model.RentsListModel',
autoLoad: true,
pageSize: 0,
proxy: {
type: 'ajax',
url: '/api/renter/',
reader: {
type: 'json',
rootProperty: 'results'
}
}
},
plugins: [{
type: //someplugins}
],
/* toolbarConfig: {
xtype:'titlebar',
docked:'top',
items:[{
xtype:'button', // it is don't work
ui:'decline',
text:'decline',
align: 'right',
action:'cancel'
}]
}, */
columns: [{
text: 'id',
dataIndex: 'id'
}, {
text: 'document',
dataIndex: 'document',
editable: true,
flex: 1
}, {
text: 'document_num',
dataIndex: 'document_num',
editable: true
}, {
text: 'legal_type',
dataIndex: 'legal_type',
editable: true
}, {
text: 'fio_represent',
dataIndex: 'fio_represent',
editable: true
}, {
text: 'position_represent',
dataIndex: 'position_represent',
editable: true,
}, {
text: 'certificate',
dataIndex: 'certificate',
editable: true,
}]
});
Here is an example of a grid with a custom form:
https://fiddle.sencha.com/#view/editor&fiddle/2ojt
// model
Ext.define('Fiddle.model.Document', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'document',
type: 'string'
}, {
name: 'type',
type: 'string'
}]
});
//view (grid)
Ext.define('Fiddle.view.DocumentGrid', {
extend: 'Ext.grid.Panel',
xtype: 'documentlist',
store: {
model: 'Fiddle.model.Document',
data: [{
id: 1,
document: 'My First Doc',
type: 'pdf'
}, {
id: 2,
document: 'My Second Doc',
type: 'pdf'
}]
},
columns: [{
text: 'id',
dataIndex: 'id'
}, {
text: 'Document',
dataIndex: 'document',
flex: 1
}, {
text: 'Type',
dataIndex: 'type',
}]
});
var form = Ext.create('Ext.form.Panel', {
title: 'Form',
region: 'east',
layout: {
type: 'vbox',
algin: 'stretch'
},
collapsible: true,
bodyPadding: 10,
hidden: true,
items: [{
xtype: 'textfield',
name: 'document',
fieldLabel: 'Document'
}, {
xtype: 'combo',
name: 'type',
fieldLabel: 'type',
store: ['pdf', 'doc', 'docx', 'odf']
}],
buttons: [{
text: 'Save',
handler: function () {
form.updateRecord();
form.hide();
}
}]
});
var grid = Ext.create('Fiddle.view.DocumentGrid', {
title: 'Document Grid',
region: 'center',
listeners: {
selectionchange: function (selModel, selection) {
if (Ext.isEmpty(selection)) {
form.hide();
return;
}
form.loadRecord(selection[0]);
form.show();
}
}
});
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
layout: 'fit',
layout: 'border',
width: 600,
height: 600,
items: [
grid, form
]
});
}
});
Ext.define('RouteFareModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'Rate_ID', type: 'number'},
{name: 'Route_Fare' , type: 'int'},
'From_LocationName',
'To_LocationName',
'From_LocationID',
'To_LocationID',
'from_name',
'to_name',
'Route_ID',
'Normal_Rate',
'Discounted_Rate']
});
var RouteFareStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteFareModel',
storeId: 'RouteFareStore',
autoLoad: false,
sorters: [{
property: 'Route_Fare',
direction: 'ASC'
}],
proxy: {
type: 'ajax',
url: 'get-routefare.php',
api: {
create: 'insert-routeseq.php',
//read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
Ext.define('MyApp.view.MyGridPanelRouteFare', {
extend: 'Ext.grid.Panel',
id:'MyGridPanelRouteFare',
alias: 'widget.mygridpanelroutefare',
renderTo: Ext.getBody(),
height: window.innerHeight,
width: window.innerWidth/3,
title: 'Route Fare Setting',
selModel: {
selType: 'cellmodel'
},
plugins: [cellEditing],
store: RouteFareStore,
columns: [
{
xtype:'gridcolumn',
width: 120,
dataIndex: 'from_name',
text: 'From Location'
},
{
xtype:'gridcolumn',
width: 120,
dataIndex: 'to_name',
text: 'To Location'
},
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Normal_Rate',
text: 'Normal Rate'
},
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Discounted_Rate',
text: 'Discount Rate'
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
height: 30,
items: [
{
xtype: 'combobox',
id:'cmbFareRouteID',
width: 191,
store: RouteNameStore,
valueField : "_id",
displayField : "Route_Code",
fieldLabel: 'Route Code',
labelWidth: 70,
editable: false,
queryMode: 'local',
listeners: {
select: function( combo, records, eOpts ) {
console.log("Combo selected _id : "+records[0].get('_id'));
RouteFareStore.load({
params:{
_id: records[0].get('_id')
}
});
}
}
},
{
xtype: 'button',
cls: '',
id: 'BtnFareCmbRefresh',
width: 65,
icon: '',
iconCls: 'refresh',
text: 'Refresh'
}
]
},
{
xtype: 'toolbar',
dock: 'top',
height: 30,
items: [
{
xtype: 'button',
cls: '',
id: 'BtnRouteFareSave',
width: 65,
icon: '',
iconCls: 'save',
text: 'Save'
},
{
xtype: 'button',
cls: '',
id: 'BtnRouteFareRefresh',
width: 65,
icon: '',
iconCls: 'refresh',
text: 'Refresh'
}
]
}
]
})
i have add
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
but the grid cell still not able to editable. why?
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Normal_Rate',
text: 'Normal Rate',
field: {
xtype: 'numberfield',
allowBlank: false,
minValue: 0,
maxValue: 1000
}
},
must insert field: {} , then the cellmodel able to editable already.
Just getting frustrated by something that should be an easy fix, but I'm too simple minded to see it :)
I'm having a grid where 1 column is a combobox. The thing works just fine and the correct value is beeing sent through my ajax request, but after I edited the grid row, the combobox disappread and the value that comes into place is not the label, but the value.
editor: new Ext.form.field.ComboBox({
typeAhead: true,
lazyRender: true,
store: new Ext.data.ArrayStore({
fields: ['contact', 'contactLabel'],
data: [
[1,'Jan'],
[2,'Jeroen'],
[3,'Mattijs'],
[4,'Sven'],
[5,'Thomas'],
[6,'Yoran']
]
}),
valueField: 'contact',
displayField: 'contactLabel',
hiddenName: 'contact'
})
So what happens is that when I change the combobox to i.e.. "Thomas", the value of the cell becomes "5", instead of "Thomas". I thought that defining value/display fields would make a difference, but it does not.
Anyone that knows the answer?
I am not quite sure if I got you right. If so you will need a renderer for that. I guess the example below the code snipped should show you if you are meaning such a case.
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
See this full working example for both (cellEditing + rowEditing) JSFiddle ()
Here's the complete code
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'id'],
data:{'items':[
{"name":"Lisa", "email":"lisa#simpsons.com", "phone":"555-111-1224","id": 0},
{"name":"Bart", "email":"bart#simpsons.com", "phone":"555-222-1234","id": 1},
{"name":"Homer", "email":"home#simpsons.com", "phone":"555-222-1244","id": 2},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254","id": 3}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the combo store
var store = new Ext.data.SimpleStore({
fields: [ "value", "text" ],
data: [
[ 0, "Option 0" ],
[ 1, "Option 1" ],
[ 2, "Option 2" ],
[ 3, "Option 3" ]
]
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'cell'
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'row'
});
html
<div id="cell"></div>
<div id="row"></div>
Try:
data: [
{contact: 1, contactLabel: 'Jan'},
...
]
![ 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');
}
},
I'm trying to load a form from a record selected in a combo.
The store is loaded properly and the combo is populated, but, when I select a value from combo, form fields remain empty.
Any help will be appreciated.
This is the code:
Model:
Ext.define('AA.model.proc.Process', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'owner', type: 'string' },
{ name: 'mail_dest', type: 'string' }
],
proxy: {
type: 'rest',
url : 'data/camp.json',
reader: {
type: 'json',
root: 'camp',
totalProperty: 'count'
}
}
});
Store:
Ext.define('AA.store.proc.Process', {
extend: 'Ext.data.Store',
model: 'AA.model.proc.Process',
requires: 'AA.model.proc.Process'
});
Class:
Ext.define('AA.view.proc.IM', {
extend: 'Ext.window.Window',
alias: 'widget.im',
title: 'IM',
layout: 'fit',
height: 500,
width: 400,
autoShow: true,
plain: true,
modal: true,
headerPosition: 'right',
closable: false,
initComponent: function () {
this.items = [{
xtype: 'form',
fileUpload: true,
width: 550,
autoHeight: true,
border: false,
bodyStyle: 'padding:5px 5px 0',
frame: true,
labelWidth: 100,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'combo',
name: 'name',
store: 'procstore',
fieldLabel: 'Name',
valueField: 'name',
displayField: 'name',
width: 150,
allowBlank: true,
listeners: {
scope: this,
'select': this.loadForm
}
}, {
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name'
}, {
xtype: 'textfield',
fieldLabel: 'Owner',
name: 'owner'
}, {
xtype: 'textfield',
fieldLabel: 'E-mail owner',
name: 'mail_dest'
}]
}];
this.buttons = [{
text: 'Save',
action: 'save'
}, {
text: 'Cancel',
scope: this,
handler: this.close
}];
this.callParent(arguments);
},
loadForm: function (field, record, option) {
console.log(record)
// firebug returns
// $className "AA.model.proc.Process"
// $alternateClassName "Ext.data.Record"
console.log(this.down('form'))
// firebug returns the right form panel
this.down('form').loadRecord(record);
}
});
This is from the documentation for the select event:
select( Ext.form.field.ComboBox combo, Array records, Object eOpts )
Notice that the second parameter is an Array. But in your example the second parameter is an Ext.data.Record. You are treating array as a record. Modify your loadForm to make it process arrays of records:
loadForm: function (field,records,option) {
this.down('form').loadRecord(records[0]);
}
P.S. By the way you have two fields with name: 'name'.