PDA

View Full Version : Get Row/Column onContextMenu of Grid



lukefowell89
22 Dec 2010, 2:22 AM
Hi,

Probably just being stupid but I cant seem to figure out how I can get the row or column details that I rightclick on?

Want to be able to remove rows and columns, but first need to be able to get a reference to the record, or column.

Heres my code:

Ext.ux.CanvasItemGrid = Ext.extend(Ext.ux.CanvasItemBox, {
constructor: function (config) {

this.defaultColumns = [];
this.defaultRows = [];
this.noOfRows = 5;
this.noOfColumns = 3;

this.defaultColumns.push(new Ext.grid.RowNumberer());

for(var x = 1; x <= this.noOfColumns; x++)
{
this.defaultColumns.push({header: x, mapping:'C'+x});
}

//this.records = [];
var rec = Ext.data.Record.create(this.defaultColumns);
this.rec = rec;

this.store = new Ext.data.ArrayStore({
fields : this.defaultColumns,
storeId : 'myStore'
});

for(var x = 1; x <= this.noOfRows; x++)
{
this.recordData = {};
for(var y = 1; y <= this.noOfColumns; y++) {
this.recordData[y] = '';
}
this.store.add(new rec(this.recordData));
}

this.component = new Ext.ux.CanvasItemGridPanel({
border : true,
bodyStyle : 'background-color: red;',
store : this.store,
colModel : new Ext.grid.ColumnModel({
defaults: {
width : 180,
sortable : true
},
columns: this.defaultColumns
}),
selModel: new Ext.grid.CellSelectionModel()

});

Ext.ux.CanvasItemGrid.superclass.constructor.call(this, Ext.apply({
name : 'Grid',
icon : 'grid.png',
type : 'gridfield',
border : true,
cls : 'dd-grid-canvas',
handles : 'all',
bodyStyle : 'background-color: red;',
items : this.component
},config));

},

initComponent: function() {
this.contextMenu = [{
text: 'Add Column',
iconCls: 'new-query',
scope: this,
handler: function()
{
var columnNo = this.items.items[0].colModel.getColumnCount();
this.items.items[0].addColumn({name: 'C'+columnNo},{header: columnNo});
}
},{
text: 'Add Row',
iconCls: 'new-query',
scope: this,
handler: function()
{
var rec = Ext.data.Record.create(this.defaultColumns);
this.store.add(new rec);
}
},{
text: 'Delete Column',
iconCls: 'formula-builder-cancel',
scope: this,
handler: function(a,b,c)
{
console.log(a,b,c)
console.log(b.getTarget());
}
},{
text: 'Delete Row',
iconCls: 'formula-builder-cancel',
scope: this,
handler: function()
{

}
}];
Ext.ux.CanvasItemGrid.superclass.initComponent.apply(this, arguments);

//notificationCenter.addObserver(D_CANVAS_POST_QUERY_LOAD, "postQueryLoad", this);
},

updateBox : function(box) {
this.setHeight(box.height);

this.component.setHeight(box.height);

this.setSize(box.width, box.height);
this.component.setSize(box.width, box.height);

this.doLayout(false, true);
this.component.doLayout(false, true);
},

config : function() {
return Ext.apply(Ext.ux.CanvasItemGrid.superclass.config.call(this), {
});
}



});
Ext.reg('canvasItemGrid', Ext.ux.CanvasItemGrid);
Thanks