PDA

View Full Version : [RESOLVED]Getting grid headers and selected record values



Kloon
10 Aug 2010, 6:14 AM
Is there a way I can get a grid's headers and then the selected records values coresponding with the headers?

what I currently have is this


var gridrecord = grid.getSelectionModel().getSelected();
var rowIndex = grid.getStore().indexOf(gridrecord);
alert(store.getAt(rowIndex).data[0]);
But that does not return the data, just undefined.

Any help would be appreciated thanks.

10 Aug 2010, 10:05 AM
record.data is an object, not an array, hence the failure.

Try store.getAt(rowIndex).get('some mapping here')

Kloon
10 Aug 2010, 9:14 PM
Okay I tried that now, my problem is I dont know what the fields are, is there a way to loop through all the columns in the selected record and also the headings of the datasource?

Kloon
10 Aug 2010, 9:41 PM
I got this sovar that returns all the row data, now I just need a way to get the corresponding headers.


var optionsHandler = function(item) {
var gridrecord = grid.getSelectionModel().getSelected();
var rowIndex = grid.getStore().indexOf(gridrecord);
var record = store.getAt(rowIndex);
for (var key in record.data) {
var obj = record.data[key];
console.log(key+' : '+obj);
}
}
key contains the mappingKey and obj the value, but I cant seem to find the mappings anywhere in the store.

Kloon
10 Aug 2010, 11:27 PM
Finally got it working, just for the others out there that would like to display a horizonal record in a grid in a vertical form here is how.


var optionsHandler = function(item) {
var gridrecord = grid.getSelectionModel().getSelected();
if (gridrecord == undefined) {
Ext.Msg.alert('Error!', 'Please select a record to view');
return;
}
var rowIndex = grid.getStore().indexOf(gridrecord);
var record = store.getAt(rowIndex);

var viewForm = new Ext.FormPanel ({
bodyStyle:'padding:5px 5px 0',
defaultType: 'displayfield',
labelWidth: 130,
frame: true,
items: []
});

for (var key in record.data) {
var obj = record.data[key];
var columnIndex = grid.getColumnModel().findColumnIndex(key);
var columnHeader = grid.getColumnModel().getColumnHeader(columnIndex);
thefield = new Ext.form.DisplayField({
fieldLabel: columnHeader,
value: obj
});
viewForm.add(thefield);
viewForm.doLayout();
}
var viewWindow = new Ext.Window({
title: 'View Record',
width: 600,
layout: 'fit',
height: 500,
maximizable: true,
modal: true,
items:[viewForm]
});
viewWindow.show();
}