PDA

View Full Version : How to read the record of A grid is selected for ext4.1.2 ?



kingbes
7 Feb 2014, 11:12 PM
I defined a advtextfield component, and is applied in the grid, How to read the record of 'userGrid' grid is selected in the advtextfield?


How to read the record of 'userGrid' grid is selected, And set the corresponding data?
How to read the record of 'userGrid' grid is selected for ext4.1.2 ?

for example:

var grid = Ext.create('Ext.grid.Panel', {
id:'userGrid',
store: store,
columns: [{
header: 'username',
dataIndex: 'username'
}, {
header: 'email',
dataIndex: 'email',
width: 160,
editor: {
allowBlank: false,
xtype: 'advtextfield' //custom advtextfield.
}
}],
renderTo:document.getBody(),
plugins: ['celleditor']
});

Ext.define("Ex.ux.form.AdvTextField",{
extends:"Ext.form.TextField",
xtype:'advtextfield',

initComponent:function(){

//How to read the record of 'userGrid' grid is selected. And set the corresponding data.
//for example ext2.0.2
if(this.record){
var userName = this.record.get("username");
var email = this.record.get("email");
this.record.set("username",'chinafeng');
this.record.set("email",'[email protected]');
}

//How to read the record of 'userGrid' grid is selected for ext4.1.2 ?
.........
}


});

kingbes
8 Feb 2014, 9:27 PM
I defined a layoutfield component, how to read the selected record of grid for ext4.1.2 in layout component? This version of the extjs2.0.2 use the variablethis.record to call the selected grid records, extjs 4.1.2 this version does not know which one to use parameters to invoke the selected records?



Ext.define('Ext.ux.grid.EditorPanel', {
extends:'Ext.grid.GridPanel',
xtype:'AdvGrid',
store: store,
columns: [
{
text : 'Company',
dataIndex:'company',
editor:new Ext.ux.form.LayoutField()

},
{
text : 'address',
dataIndex: 'address'
}]
});


Ext.define("Ext.ux.form.LayoutField",{
extends:'Ext.form.field.Trigger',
xtype:'layoutfield',
onTriggerClick:function(){

/* This version of the extjs2.0.2 use the variable this.record to call the selected grid records, extjs 4.1.2 this version does not know which one to use parameters to invoke the selected records?
*/

//use extjs2.0.1 for example
if(this.record){
alert(this.record.data.company)
}

// how to implement for extjs4.1.2
// I want not use code 'Ext.getCmp('userGrid').getSelectionModel().getSelected()' to get the record
//how to do


}

});

palakurthivishal
9 Feb 2014, 8:08 AM
Hello ,
I'm not sure what you are asking but please look into the docs of grid component. You can get the selected records of a grid from the selection model you have applied.
Eg: grid.getSelectionModel().getSelection(); this method returns array of selected records.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.panel.Table-method-getSelectionModel
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.selection.Model-method-getSelection

kingbes
9 Feb 2014, 6:34 PM
thank your reply!

Ext.ux.form.Layout as a column editor component GridPanel. When I click on the cell GridPanel. Show the layoutfied component, how to get when GridPanel was selected rows in layoutfield.

In the extjs2.0.2 version it is to transfer the selected rows using the 'this.record' variable. This version of extjs4.x is how to transfer? Because I do not know the current definition of GridPanel ID, so I can't use the code 'Ext.getCmp ().getSelectionModel.getSelection()' to get it.

kingbes
10 Feb 2014, 12:07 AM
I know how to write the code.
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
startEdit: function(record, column) {
column.field.record = record; // use the paramter of record
return this.self.prototype.startEdit.call(this, record, column);
}
});