PDA

View Full Version : help with EditorGrid



jpmm
4 May 2007, 10:10 AM
Whenever I try to edit a cell and get the field name in a simple alert box (in the afterEdit function) I always get field undefined. How can I get the field name from the grid headers. Thanks a lot in advance. Here is my code:



EditorExample = function(){

// define some private variables
var dialog, showBtn;

var dataModel;
var grid;
var colModel;

var getURL='ideas-data.php';
var updateURL='update-ideas.php';

var formatImage = function(value){
value = (value == -1) ? "null" : "<img src='/img/" + value + "'/>";
return value;
};

return {
init : function() {

var yg = YAHOO.ext.grid;

var sort = YAHOO.ext.grid.DefaultColumnModel.sortTypes;

var cols = [{
header: "Image",
width: 50,
renderer: formatImage
},{
header: "ID",
width: 50,sortable: true, sortType: sort.asUCString,
sortable: true
},{
header: "Title",
width: 350,sortable: true, sortType: sort.asUCString,
sortable: true,
editor: new yg.TextEditor({allowBlank: false})
},{
header: "Self Assessment Description",
width: 2400,sortable: true, sortType: sort.asUCString,
sortable: true,
editor: new yg.TextEditor({allowBlank: false})
},{
header: "Other Description",
width: 2400,sortable: true, sortType: sort.asUCString,
sortable: true,
editor: new yg.TextEditor({allowBlank: false})
}];
colModel = new YAHOO.ext.grid.DefaultColumnModel(cols);
colModel.defaultSortable = true;

var schema = {
tagName: 'plant',
id: 'use-index',
fields: ['image', 'ideaid', 'ideiatitle', 'sadescription', 'otherdescription']
};
dataModel = new YAHOO.ext.grid.XMLDataModel(schema);
dataModel.setDefaultSort(colModel, 0, "ASC");

grid = new YAHOO.ext.grid.EditorGrid('example-grid', dataModel, colModel);
// to use double click to edit:
grid.getSelectionModel().clicksToActivateCell = 2;
grid.trackMouseOver=true;
grid.on('afteredit', this.afterEdit, this, true);
grid.render();
this.loadDataModel(getURL)

},



afterEdit : function(grid, row, field, rowIndex, columnIndex){

alert("Field: ".field);

/*
var ed = this.grid.getColumnModel().getCellEditor(columnIndex, rowIndex);
var value = ed.getValue();

var rowId = row.id;
var url = this.updateURL;
var conn = new Ext.data.Connection();
conn.request({
url: url,
params: {
pageUrl: getPageUrl(),
rowId: rowId,
field: field,
value: value
}
});
*/
},


loadDataModel : function(url){

var success = function(o){
try{
var xml = o.responseXML;
dataModel.loadData(xml);
}catch(e){
alert(e);
}
}.createDelegate(this);
var failure = function(o){
alert("failure");
};
YAHOO.util.Connect.asyncRequest('POST', url, {success:success, failure:failure}, '');
}

};
}();

YAHOO.ext.EventManager.onDocumentReady(EditorExample.init, EditorExample, true);

jsakalos
4 May 2007, 10:14 AM
I you want your question to be answered faster enclose your code in php tags

tryanDLS
4 May 2007, 11:18 AM
I suggest you migrate to the Ext 1.0 codebase - you're going to find very few users able to answer questions about the old code. Review the examples and tutorials for the way to use the grid/store/proxy in the new format.