PDA

View Full Version : getting row data from grid



coooolmagic
25 Jun 2010, 7:37 AM
Hi all

i am using grid with grouping store. everything works find.
I am trying to get data of selected row in the grid. Can you suggest the best way to get the values?

thnaks

wm003
25 Jun 2010, 7:40 AM
Use a listener:



rowclick: function(grid,index,e) {

var clickedRow = grid.store.getAt(index);
alert(Ext.encode(clickedRow.data));

},

coooolmagic
25 Jun 2010, 7:57 AM
some how this function is not getting called at all. here is my grid:


var grid = new xg.GridPanel({
store: store,
frame:true,

height: 620,
layout:'fit',
collapsible: true,
animCollapse: true,
title: 'SCM Transactions',
iconCls: 'icon-grid',
//fbar : ['->', {
// text:'Clear Grouping',
// iconCls: 'icon-clear-group',
// handler : function(){
// store.clearGrouping();
// }
//}],

columns: [
{id:'document_name',header: "Transaction Name", width: 60, sortable: true, dataIndex: 'document_name'},
{header: "Folder Path", width: 20, sortable: true, dataIndex: 'folder_path'},
{header: "Document Type", width: 20, sortable: true, dataIndex: 'document_type'},
{header: "Transaction", width: 20, sortable: true, dataIndex: 'transaction',hidden:true},
{header: "Object Id", width: 20, sortable: true, dataIndex: 'objectid',hidden:true},
{header: "Modify Date", width: 20, sortable: true, dataIndex: 'document_modification_date'}
],

view: new Ext.grid.GroupingView({
forceFit:true,
startCollapsed:true,
groupTextTpl: '{group} ({[values.rs.length]} {[values.rs.length > 1 ? "Documents" : "Item"]})'
}),

bbar: new Ext.PagingToolbar({
pageSize: 10,
store: store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed){
var view = grid.getView();
view.showPreview = pressed;
view.refresh();
}
}]
}),

rowclick: function(grid,index,e) {
var clickedRow = grid.store.getAt(index);
alert(Ext.encode(clickedRow.data));

},


renderTo: document.body
});

Animal
25 Jun 2010, 9:26 AM
It's an event not a config. See the listeners config.

coooolmagic
28 Jun 2010, 1:37 AM
thanks. got this sorted out.

When I get the row data, it gives me in the form of JSON object.

Is there any easy way to get value of any attribute out of that json object?

Condor
28 Jun 2010, 1:45 AM
Ext.data.Store.getAt() returns an Ext.data.Record instance, which has a get(fieldname) method (see API docs).

Animal
28 Jun 2010, 1:45 AM
There's no such thing as a json object.

You are running Javascript.

It's an object.

coooolmagic
28 Jun 2010, 1:51 AM
Thank you so much every one for such a quick and great help. I am extreamly sorry for such a fundamental qs, have booked training already in next month.

Animal
28 Jun 2010, 2:04 AM
No problem asking basic questions. You picked up the gist of what we were saying pretty quick, which is good!