0

我有telerik网格。

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

通过单击该行,我需要知道单元索引(单击的那个)。
我有这个功能:

function onRowSelect(e){}

我如何从那里提取它?

4

2 回答 2

0

您无法通过 RowSelect 事件检索列索引。

一旦网格初始化(通过 OnLoad 事件),我建议您像这样附加自己的委托事件:

function onGridLoad(){
    $(this).data().tGrid.$tbody.on('click','td',function(e){
        alert('COLUMN INDEX: '+$(this).index())
    })
}
于 2013-03-03T18:35:02.500 回答
0

我的回答是基于这个问题,归功于jQuery 中的 Table row and column number

试试这个:

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.
于 2013-03-07T01:18:00.360 回答