View Full Version : show gird column value in a text box

2 Mar 2012, 10:30 PM

I have a window with a form panel , a grid and 2 buttons OK and Close. The grid columns are populated with values from db using the data store and reader. I wanted to select 2 grid columns and when I click the Ok button it should display those selected grid values in a text box(two values separated by colon).
I have written a javascript function which closes the window and then displays a text box on click of the OK button. But I am not sure how to get the grid column values to the text box.
Could somebody please help me on this.
Thanks in advance...

2 Mar 2012, 11:06 PM
1. To get value of a field from selected row:

var selectedRecord = grid.getSelectedModel().getLastSelected();
var fieldValue = selectedRecord.get('fieldName');

2. To set value for a textbox


4 Mar 2012, 7:32 PM
Thanks Vietits for the reply..I tried your solution. But its not displaying the value.

var selectedRecord = pidGrid.getSelectedModel().getLastSelected();
var fieldValue = selectedRecord.get('pid');

pidGrid - name of my grid ; pid - dataindex of the selected grid column ; pidVal - text box id to which the value needs to be updated.

Please let me know if I am missing anything here.
thanks in advance...

4 Mar 2012, 8:50 PM
Hi Vietits,
I was able to alert the selected grid value using
var selectedRecord = Ext.getCmp('pidList').getSelectionModel().getSelected().get('pid');

But not able to set the value to the text box created using

This grid is in a separate pop up window and the text box is in another form. When we click a button on this form, it opens this window which is having the grid. So after selecting the grid column and clicking on Ok, should close the window and set the text box with the selected grid value.
var selectedRecord = Ext.getCmp('pidList').getSelectionModel().getSelected().get('pid');
alert(selectedRecord); // The selected value is alerted here.
Ext.getCmp('pidVal').setValue(selectedRecord); //pidVal - text box id

This is not working...Could somebody please help me here...

4 Mar 2012, 11:24 PM
what's the output ?

1. get rid of Ext.getCmp
2. use console.log instead of alert

4 Mar 2012, 11:40 PM
1. You made a mistake in your code. Correct it as below:

// var selectedRecord = Ext.getCmp('pidList').getSelectionModel().getSelected().get('pid');
var selectedRecord = Ext.getCmp('pidList').getSelectionModel().getLastSelected().get('pid');
alert(selectedRecord); // The selected value is alerted here.

2. Setting value for textbox: The code below works well for me.

Ext.onReady(function() {
var form = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
border: false,
items: [{
fieldLabel: 'pid Value',
id: 'pidVal',
xtype: 'textfield'
Ext.getCmp('pidVal').setValue('this is selected pid value');