PDA

View Full Version : Get grid rowIndex on drop



torvad
3 Aug 2007, 1:57 AM
Hi,
I've been searching the forum but no luck so far.

I have a tree from which I drag tree leafs to a grid. On then event handler for noifyDrop on the grid I am trying to get the index of the row that I'm dropping my tree data on. I need the rowIndex for my insert in the datastore.

I've tryed few things I've found in the forum, but I think they all were regardning D&D within/between grids. I am new to ext and the javascript model so I the answer is obvius, I can't see it.

(I'm using xsl/xml to create components)

My code:

var ddrow = new Ext.dd.DropTarget(grid.container, {
ddGroup : '<xsl:choose><xsl:when test="@ddGroup"><xsl:value-of select="@ddGroup"/></xsl:when><xsl:otherwise></xsl:otherwise></xsl:choose>',
copy:false,
notifyDrop : function(dd, e, data){

if(!data.node)
{
//DEBUG
//alert('handle internal grid DD or sort');

var sm=grid.getSelectionModel();
var rows=sm.getSelections();

var cindex=dd.getDragData(e).rowIndex;

for (i = 0; i <xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text> rows.length; i++) {
rowData=JsonData.getById(rows[i].id);
if(!this.copy) {
JsonData.remove(JsonData.getById(rows[i].id));
JsonData.insert(cindex,rowData);
}
};
}
else
{
//DEBUG
//alert('drop from tree ' + data.rowIndex);

//HERE is by head scratcher!!!!
var cindex=0;//dd.getDragData(e).rowIndex;

var rowData = new RecordDef({

<xsl:for-each select="sx:ext-grid-column/sx:ext-grid-cm">

<xsl:if test="position()&gt;1">,</xsl:if>
<xsl:value-of select="@dataIndex"></xsl:value-of>:'1'
</xsl:for-each>
});

if(!this.copy){
JsonData.insert(rowIndex, rowData);
}
else{
alert('is a copy');
return false;
}
}

}
});

torvad
7 Aug 2007, 4:01 AM
Hi,
I found the ansver in vtswingkids thread.
http://extjs.com/forum/showthread.php?t=9390



Add the following to your grid definition:

listeners:{
scope:this,
'mouseup':{scope:this.grid, fn:function(e, t){
var row;
if((row = this.view.findRowIndex(t)) !== false)this.rowMouseUp=row;
else this.rowMouseUp=false;
}}
}

Then in notifyDrop:

var cindex=grid.rowMouseUp;

Got the index :)

Ben
22 Aug 2007, 1:34 AM
Brilliant!

Thanks. That's solved my problem with row selection before I even posted it!

Ben