PDA

View Full Version : How to get the ID of a grid when i click a button present in the tbar of the grid??



pitviper202002
21 Aug 2009, 5:46 AM
HI,

My scenario is as follows

i create grid and render it into a formpanel on the click of a button as follows

phaseTaskGrid = new Ext.grid.GridPanel({
title : phaseTitle,
//id : 'phaseTaskGridID',
height : 130,
width : 770,
renderTo : 'test',
autoScroll : true,
collapsible : true,
frame : true,
store : new Ext.data.SimpleStore({
fields : [{
name : 'gridTaskName'
}, {
name : 'gridOwnerName'
}, {
name : 'gridTaskStartDt'
}, {
name : 'gridTaskEndDt'
}

]
}),
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
}),
stripeRows : true,
columns : [{
header : "Name",
sortable : true,
dataIndex : 'gridTaskName',
width : 100
}, {
header : "Owner",
sortable : true,
dataIndex : 'gridOwnerName',
width : 180
}, {
header : "Start Date",
sortable : true,
dataIndex : 'gridTaskStartDt',
width : 180
}, {
header : "End Date",
sortable : true,
dataIndex : 'gridTaskEndDt',
width : 180
}],
tbar : [{
text : 'New Task',
iconCls : 'save',
handler : function() {
alert(phaseTaskGrid.getId())
phaseTaskWindow.show()
}
}]
});

i thus create multiple grids .Each grid has a button in its tbar which on click renders a pop up window .On click of the submit button of the pop up window i want data from it to create a new row in respective grid but instead row is always added to the last grid created.Creating new record as follows

handler : function() {
var newTaskRecord = new Ext.data.Record({
gridTaskName : Ext.getCmp('taskName').getValue(),
gridOwnerName : Ext.getCmp('taskOwner').getValue(),
gridTaskStartDt : Ext.getCmp('taskStartDt')
.getValue().format('d-M-Y'),
gridTaskEndDt : Ext.getCmp('taskEndDt').getValue()
.format('d-M-Y')

})
var gridId=phaseTaskGrid.getId()
Ext.getCmp(gridId).stopEditing();
Ext.getCmp(gridId).getStore().insert(0,
newTaskRecord);
// Ext.getCmp('phaseTaskGridID').startEditing(0, 0)
phaseTaskWindow.hide()
}

Can anyone guide me so as how to identify the grid on button click so that row is created in the required grid

pitviper202002
22 Aug 2009, 3:13 AM
Please help really stuck with this problem

Condor
22 Aug 2009, 3:21 AM
handler: function(){
var grid = this.findParentByType('editorgrid');
var newTaskRecord = new (grid.getStore().recordType)({
gridTaskName: Ext.getCmp('taskName').getValue(),
gridOwnerName: Ext.getCmp('taskOwner').getValue(),
gridTaskStartDt: Ext.getCmp('taskStartDt').getValue().format('d-M-Y'),
gridTaskEndDt: Ext.getCmp('taskEndDt').getValue().format('d-M-Y')
});
grid.stopEditing();
grid.getStore().insert(0, newTaskRecord);
// grid.startEditing(0, 0);
phaseTaskWindow.hide()
}

pitviper202002
22 Aug 2009, 3:39 AM
Hi Condor,

i did as u mentioned but im getting the following error

grid is null
handler()()dynamic.js (line 199)
DomHelper()(Object browserEvent=Event mouseout button=0 type=mouseout)ext-all.js (line 8)
A()ext-all.js (line 8)

chrome://firebug/content/blank.gif var newTaskRecord = new (grid.getStore().recordType)({

Condor
22 Aug 2009, 3:42 AM
You are using a GridPanel, so it should be:

var grid = this.findParentByType('grid');

(I got confused; why did you call stopEditing if it's not an EditorGridPanel?)

pitviper202002
22 Aug 2009, 3:52 AM
Thanks a lot Condor was struggling with this from yesterday.

viper