Basics of GridPanel
PHP Code:
var fields = [
{name:'Id', mapping:'Id'},
{name:'Code', mapping:'Code'},
{name:'Name', mapping:'Name'}
];
var cols = [
{ id : 'Id', header: "Identity", width: 160, sortable: true, dataIndex: 'Id'},
{header: "Code", width: 50, sortable: true, dataIndex: 'Code'}
];
var vp = new Ext.Viewport({
... shortended code
xtype:"panel",
title:"Selection",
id:"selectionTab",
disabled:true,
items:[
new Ext.grid.GridPanel({
id:"grdSelectionLeft",
ddGroup : 'leftGridDDGroup',
store:{},
columns : cols,
enableDragDrop : true,
stripeRows : true,
title : 'Services Available',
height:400,
width:400
}),
new Ext.grid.GridPanel({
id:"grdSelectionRight",
ddGroup : 'rightGridDDGroup',
store : {},
columns : cols,
enableDragDrop : true,
stripeRows : true,
title : 'Services Selected',
height:400,
width:400
})
]
}); // End of Viewport
/* NOTE ISSUE IS HERE */
/*
Also tried creating a GridPanel within a variable
(ie var grdPanel1 = new Ext.grid...) so I have also
done:-
var ddrow = new Ext.dd.DropTarget(grdPanel1.getView().mainBody...
Same applies to trying getView().el.dom, all of which return null/error
More will be described after this code
*/
var ddrow = new Ext.dd.DropTarget(Ext.getCmp("grdSelectionLeft").getView().mainBody, {
ddGroup : 'mygrid-dd',
notifyDrop : function(dd, e, data){
var sm = grid.getSelectionModel();
var rows = sm.getSelections();
var cindex = dd.getDragData(e).rowIndex;
if (sm.hasSelection()) {
for (i = 0; i < rows.length; i++) {
store.remove(store.getById(rows[i].id));
store.insert(cindex,rows[i]);
}
sm.selectRecords(rows);
}
}
Firstly, Yes, the code inside Ext.dd.DropTarget does not match the code I done above. This is not whats causing the error. The code was copied and pasted from another site. Basically, I added a break point to the area causing the problem and went through the available properties in Ext.getCmp("grdSelectionLeft") and Ext.getCmp("grdSelectionLeft").getView() and cannot for the life of me find the correct dataset required.
So, I have tried getCmp, getDom, and (I think) getBody. Also, as mentioned in the comment, I also created the GridPanel into a variable. This follows the examples from other sites and from a book. However, the result is the same.
just to demonstrate: -
var grdPanel = new Ext.grid.GridPanel({...})
I add it to my viewport (replacing the code above with it's var equiverlant)
in the last portion, I use: -
Ext.dd.DropTarget(grdPanel .getView().mainBody
Result is the same.
Could using the specific 'renderTo' property be the reason for all of this?
I shall have to try this method and get back to you.
Any questions, or suggestions, and I will reply as soon as I can.
Many thanks.