rothaar
20 Feb 2009, 12:57 PM
Hello again all,
I'm playing with an EditorGridPanel and running into a little trouble. From several other posts I've read it seems that maybe I'm messing around with an uncomfortable amount of undocumented/unsupported features, but I'm getting close to what I want to do.
My EditorGridPanel will eventually allow the user to add columns to the grid via a combotree-type object (currently it just adds an auto-numbered faux-column via a tbar button), and I'd LIKE them to be able to dismiss or close a column via a small "x" icon or something in the column header.
Unless I'm misunderstanding the API Docs, it seems that the "header" config option on a columnModel allows only string input. I suppose I could slap in HTML (see my example code) and get a reasonable result, but it feels like a filthy hack.
Has anyone had any experience extending or overriding the columnModel to allow for non-strings within? I've had no luck finding such a modification on the forums, but my google ninja skills are admittedly rusty.
Here's the code I'm working with, along with the truly fugly HTML (just slapped an alert in there for testing purposes... I would eventually need to call actions.removeDataPoint in that trigger).
var actions = {
addDataPoint: new Ext.Action({
text: _('Add'),
handler: function(){
var dpName = 'dataPoint ' + ++intAutoNumber;
var grid = Ext.getCmp('grdRawData');
var colConfig = grid.getColumnModel().config;
var headerHTML = '<div>' + dpName + ' <a href="#" onClick="alert(\'CLICK\'); return false">x</a></div>'
colConfig.push({
header: headerHTML,
dataIndex: dpName,
editor: new Ext.form.TextField({
})
});
grid.getColumnModel().setConfig(colConfig, true);
grid.reconfigure(grid.getStore(), new Ext.grid.ColumnModel(colConfig));
}
}),
removeDataPoint: new Ext.Action({
text: _('Remove'),
handler: function(sender, e){
var grid = Ext.getCmp('grdRawData');
var selModel = grid.getSelectionModel();
var colModel = grid.getColumnModel();
var selColumnIdx = selModel.getSelectedCell()[1];
var selColumnId = colModel.getColumnId(selColumnIdx);
var selColumnObj = colModel.getColumnById(selColumnId);
if (!selColumnObj.noDelete) {
var colConfig = colModel.config;
var selDataIndex = colModel.getDataIndex(selColumnIdx)
colConfig.splice(colConfig.IndexOfByMember('dataIndex', selDataIndex), 1);
for (var i=1; i<colConfig.length; i++) {
delete colConfig[i].id;
}
colModel.setConfig(colConfig, true);
grid.reconfigure(grid.getStore(), new Ext.grid.ColumnModel(colConfig));
}
}
})
}
var win = new Ext.Window({
title: _('Raw Data Editor'),
width: 750,
height: 500,
layout: 'border',
constrain: true,
modal: true,
plain: true,
closable: false,
bodyStyle: 'padding: 5px;',
buttonAlign: 'center',
items: new Ext.grid.EditorGridPanel({
id: 'grdRawData',
region: 'center',
//clicksToEdit: 1,
store: rawDataStore,
enableHdMenu: false,
cm: new Ext.grid.ColumnModel([
{
header: 'Time',
dataIndex: 'time',
noDelete: true
}
])
}),
tbar: [
actions.addDataPoint,
actions.removeDataPoint
]
});
Anyone have any relevant examples of extending or overriding the ColumnModel code in this way, or should I stick with the yucky HTML insertion?
I'm playing with an EditorGridPanel and running into a little trouble. From several other posts I've read it seems that maybe I'm messing around with an uncomfortable amount of undocumented/unsupported features, but I'm getting close to what I want to do.
My EditorGridPanel will eventually allow the user to add columns to the grid via a combotree-type object (currently it just adds an auto-numbered faux-column via a tbar button), and I'd LIKE them to be able to dismiss or close a column via a small "x" icon or something in the column header.
Unless I'm misunderstanding the API Docs, it seems that the "header" config option on a columnModel allows only string input. I suppose I could slap in HTML (see my example code) and get a reasonable result, but it feels like a filthy hack.
Has anyone had any experience extending or overriding the columnModel to allow for non-strings within? I've had no luck finding such a modification on the forums, but my google ninja skills are admittedly rusty.
Here's the code I'm working with, along with the truly fugly HTML (just slapped an alert in there for testing purposes... I would eventually need to call actions.removeDataPoint in that trigger).
var actions = {
addDataPoint: new Ext.Action({
text: _('Add'),
handler: function(){
var dpName = 'dataPoint ' + ++intAutoNumber;
var grid = Ext.getCmp('grdRawData');
var colConfig = grid.getColumnModel().config;
var headerHTML = '<div>' + dpName + ' <a href="#" onClick="alert(\'CLICK\'); return false">x</a></div>'
colConfig.push({
header: headerHTML,
dataIndex: dpName,
editor: new Ext.form.TextField({
})
});
grid.getColumnModel().setConfig(colConfig, true);
grid.reconfigure(grid.getStore(), new Ext.grid.ColumnModel(colConfig));
}
}),
removeDataPoint: new Ext.Action({
text: _('Remove'),
handler: function(sender, e){
var grid = Ext.getCmp('grdRawData');
var selModel = grid.getSelectionModel();
var colModel = grid.getColumnModel();
var selColumnIdx = selModel.getSelectedCell()[1];
var selColumnId = colModel.getColumnId(selColumnIdx);
var selColumnObj = colModel.getColumnById(selColumnId);
if (!selColumnObj.noDelete) {
var colConfig = colModel.config;
var selDataIndex = colModel.getDataIndex(selColumnIdx)
colConfig.splice(colConfig.IndexOfByMember('dataIndex', selDataIndex), 1);
for (var i=1; i<colConfig.length; i++) {
delete colConfig[i].id;
}
colModel.setConfig(colConfig, true);
grid.reconfigure(grid.getStore(), new Ext.grid.ColumnModel(colConfig));
}
}
})
}
var win = new Ext.Window({
title: _('Raw Data Editor'),
width: 750,
height: 500,
layout: 'border',
constrain: true,
modal: true,
plain: true,
closable: false,
bodyStyle: 'padding: 5px;',
buttonAlign: 'center',
items: new Ext.grid.EditorGridPanel({
id: 'grdRawData',
region: 'center',
//clicksToEdit: 1,
store: rawDataStore,
enableHdMenu: false,
cm: new Ext.grid.ColumnModel([
{
header: 'Time',
dataIndex: 'time',
noDelete: true
}
])
}),
tbar: [
actions.addDataPoint,
actions.removeDataPoint
]
});
Anyone have any relevant examples of extending or overriding the ColumnModel code in this way, or should I stick with the yucky HTML insertion?