2013-03-03 159 views
0

我已經有了telerik網格。onRowSelect:如何獲取細胞索引

@(Html.Telerik().Grid(Model) 
     .Name("Grid") 
     .Columns(columns => 
     { 
      //columns & bound 
     }) 
     .ClientEvents(e=> e.OnRowSelect("OnRowSelect")) 

通過點擊行,我需要知道cellindex(一點擊)。
我具備的功能:

function onRowSelect(e){}

如何從那裏提取它?

回答

0

您無法通過RowSelect事件檢索列索引。

我建議你一旦網格是(通過OnLoad事件)初始化附上自己委託的事件是這樣的:

function onGridLoad(){ 
    $(this).data().tGrid.$tbody.on('click','td',function(e){ 
     alert('COLUMN INDEX: '+$(this).index()) 
    }) 
} 
+0

jQuery的不標記。 – 2013-03-03 18:37:20

0

我的答案是基於這個問題,信貸Table row and column number in jQuery

試試這個如下:

的Javascript:

<script> 
    function OnDataBound() { 
     // #Grid needs to match the name of the grid in View's markup. 
     $('#Grid table td').click(function() { 
      var col = $(this).parent().children().index($(this)); 
      var row = $(this).parent().parent().children().index($(this).parent()); 
      alert('Row: ' + row + ', Column: ' + col); 
     }); 


     //As a side note, you can get at the contents of the row selected with 
     //something along these lines: 
     //(this will not work unless you substitute the "EmployeeId" id with a valid one from your model. 
     $('#Grid table tr').dblclick(function() { 
      alert($(this).find("span[id=EmployeeId]")[0].innerText); //EmployeeId is just a column name used for example purposes. 
     }); 
    } 



</script> 

網格標記:

@(Html.Telerik().Grid(Model) 
    .Name("Grid") 
    .Columns(columns => 
    { 
     //columns & bound 
    }) 
    .ClientEvents(e=> e.OnDataBound("OnDataBound")) // This changed to a OnDataBound event. 
+0

@Refael - 你是否實現了你正在尋找的功能? – Igorrious 2013-03-13 17:10:47