PDA

View Full Version : [CLOSED] How to get column index of a gridpanel using javascript.



arjunrvasisht
Apr 29, 2015, 6:03 AM
Hello,

I have gridpanel with 2 columns. On clicking any of the rows I need to populate a different grid. Using the item click event of the Grid view I could achieve the functionality. Below is the code I have used. Now, I want the itemclick event to be fired only when i click on the first column. It should not fire for the second column. Though the below java script I could get only the rowindex. If I get column index then i can restrict it from being fired. How do I get the column index. Please help.

Javascript function:

var loadTier3 = function(record, item, index, e, eOpts ){
var tier2 = record.store.data.getAt(e).data.Tier2
Ext.net.DirectMethods.check(tier2);
}

This is the Gridview where am calling the above funct:


<View>
<ext:GridView ID="GrdViewMetrics" runat="server" MarkDirty="false" StripeRows="false" TrackOver="false">
<Listeners>
<ItemClick Fn="loadTier3">
</ItemClick>
</Listeners>
</ext:GridView>
</View>

EnZo
Apr 29, 2015, 6:47 AM
Hi arjunrvasisht

I would recommend using


item.cellIndex

It returns the index of the cell clicked which corresponds to the index of the column.

So if you want to check for the first column please use


if (item.cellIndex == 0)

arjunrvasisht
Apr 29, 2015, 8:07 AM
Hi EnZo,

There is no such property under item. item.cellIndex is undefined.!!

EnZo
Apr 29, 2015, 8:17 AM
Hi arjunrvasisht

Apologies. I am using Ext 3.1, it must not be available in Ext 2.x.

In this case, I would recommend using CellClick instead of ItemClick

Please view below


<ext:GridView ID="GrdViewMetrics" runat="server" MarkDirty="false" StripeRows="false" TrackOver="false">
<Listeners>
<CellClick Fn="loadTier3" />
</Listeners>
</ext:GridView>

And corresponding JavaScript


var loadTier3 = function (panel, htmlTD, cellIndex, record, tr, rowIndex, e, eOpts) {
if (cellIndex == 0)
// your code here
}

arjunrvasisht
Apr 29, 2015, 8:38 AM
Thanks EnZo. Its working great.!!
I have few rows in a disabled state. Is there a way I will get to know if the row is disabled or not through this function. Because, if its disabled i will not fire the click event.

EnZo
Apr 29, 2015, 8:53 AM
Glad to know it's working.

How exactly are the rows being disabled? Are they given a CSS class? Is there a certain attribute that could be checked through record.data?