PDA

View Full Version : Accessing whole record from cellEditor



1099511627776
17 May 2012, 12:46 AM
Hello guys,
I've created a custom field editor by extending "Ext.form.field.picker", it works fine by changing record value with setValue method. But I need to have access to record whole record

So is there any way to access whole record that contains cell which is being edited ?

scottmartin
17 May 2012, 5:45 AM
Can you please clarify what you are trying to do? 1 editor for the entire row of fields?

Scott.

1099511627776
17 May 2012, 10:53 PM
Let's sey that I have a model that looks like this:


fields:[
{name: 'article',type:'string'},
{name: 'brand',type:'string'},
{name: 'name', type:'string'},
{name: 'quantity', type:'float'},
{name: 'price', type:'float'}
]

I have a custom cell editor that selects an "article" from a dictionary. Besides article that dictionary has fields "name" and "brand". Now I want the model's fields "brand" and "name" to be filled with corresponding data right after I choosed an "article" from. By using setValue method (Ext.form.field.<Field>.setValue) I can only fill the "article" field and I don't know how to get access to other fields

scottmartin
24 May 2012, 10:41 AM
Will model.set(field,value) work for you?

Scott.

1099511627776
25 May 2012, 3:55 AM
No, it will not help, because I'm accessing editable field from cellEditor, and it has no method or property named set(field,value).
in cellEditor i have only setValue and setRawValue method but thay can access only current editable field

1099511627776
5 Jun 2012, 3:44 AM
I think i've found the solution:
first of all we need to define a new editing plugin based on CellEditing and redefine it's getEditor method:


Ext.define('ASV.metaobjects.system.docCellEditing',{
alias:'plugin.docCellediting',
extend:'Ext.grid.plugin.CellEditing',
getEditor:function(record,column){
var result = this.callParent(arguments);
result.field.wholeRecord = record;
return result;
}
});

than, somewhere in code we replace definition of cellEditing plugin with out implementation:


var cellEditingBody = Ext.create('Ext.grid.plugin.CellEditing',{
REPLACE WITH
var cellEditingBody = Ext.create('ASV.metaobjects.system.docCellEditing',{


now whe can access whole record through fields property wholeRecord and set what we need



onSelect:function(rec){
var record = null;
if(rec != null){
if (rec.hasOwnProperty('length')) {
record = rec[0];
} else {
record = rec;
}
this.setValue(record.get('article'));
this.wholeRecord.set('price',record.get('inprice'));
}
this.focus();
this.collapse();
}