View Full Version : get value from JSON

16 Nov 2010, 6:26 AM
Hi guys, Iam not able to get the values from json object.
I have a grid where the user choice the register and click in modify.
So It opens the popup with the register's informations.
I get the informations thus:

var grid = Ext.ComponentMgr.get('gridProduto');
var sm = grid.getSelectionModel();
var sel = sm.getSelected();

if (sm.hasSelection()){

Some fields I am able to set.
But some fields aren't in the grid. They are only in the JSON.
Does anyone know how to get these values that are from JSON?

16 Nov 2010, 7:14 AM
getSelected() returns the associated record with the selected row, meaning that it doesn't matters which columns are displayed in the grid, all fields in the record will be accessible. If some properties arent there, you should check your record's field definition to make sure the fields are there.

16 Nov 2010, 8:11 AM
It wasn't work scarsick.
I put a alert sel.get('dimensaoLargura') and it appears how undefined.
The json +or- thus

"statusComercial":0,"statusEditorial":0,"stringColecao":"Não","titulo":"O SUMIÇO DAS PALAVRAS"}

The colecao and dimensaoLargura fields aren't from grid.
And I am not able to get the values these fields.
I tried to get the value thus

var item = Ext.util.JSON.decode(resp.responseText);

But it also wasn't work.

16 Nov 2010, 8:43 AM
Can you show me your store's code?

16 Nov 2010, 9:19 AM
My code is as follows:

columns: [
{header: "Codigo", dataIndex: 'idProduto', sortable: true},
{header: "Titulo", dataIndex: 'titulo', sortable: true,width: 300},
{header: "Edicao", dataIndex: 'edicao', sortable: true,width: 50},
{header: "Ano", dataIndex: 'ano', sortable: true,width: 50}

16 Nov 2010, 9:30 AM
try adding a rowselect listener to your gridpanel

sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(selModel, row, record) {
// On row select, get record and value

var dim = record.get('dimensaoLargura');
alert('Dim value: '+dim);
// to set value
record.set('dimensaoLargura', 'my new value');


16 Nov 2010, 9:31 AM
It was work =))

I add every fields but I put hidden="true" on fields that I don't want that appears.
Thank's =))

16 Nov 2010, 10:15 AM
@chuvinha, You don't have to do this, and it's better for performances to only render what you need. Don't put columns that you don't need, unless you really want to user to be able to show/hide these columns.