0

在 EditForm 模式下,我有一个包含所有行的 RadGrid。此 Radgrid 具有虚拟滚动功能。我需要跳转(滚动)到特定的行。

我尝试了几种选择。在这种情况下,将一行放入 select 中不适用。我现在尝试过:

RadScriptManager.RegisterStartupScript(Page, typeof(RadGrid), "myScript", "scrollItemToTop('" + e.Item.ClientID + "');", true);

在 ItemDataBound 中,但是:

function scrollItemToTop(itemID) { $('.rgVragenPanel').scrollTo(0, $telerik.$($get(itemID)).offset().top); }

似乎不起作用。

关于如何最好地解决这个问题的任何想法?

4

1 回答 1

1

试试这个滚动到所选项目

我在数据绑定事件中选择后面代码中的项目。

   Set one of the items in the control as selected.
Provide a handler for the client-side GridCreated event.

    In the event handler, locate the selected row using the GridTableView object's get_selectedItems() method.

    Use the RadGrid object's GridDataDiv property to access the DOM element for the scrollable region of the grid.

    Use the DOM element for the row to check if it is visible in the scrollable region. If it is not, set the scrollTop property of the scrollable region to scroll the grid so that the selected row is showing. 

以下示例演示了这种技术: CopyJavaScript

<script type="text/javascript">
function GridCreated(sender, eventArgs) {
    //gets the main table scrollArea HTLM element  
    var scrollArea = document.getElementById(sender.get_element().id + "_GridData");
    var row = sender.get_masterTableView().get_selectedItems()[0];

    //if the position of the selected row is below the viewable grid area  
    if (row) {
        if ((row.get_element().offsetTop - scrollArea.scrollTop) + row.get_element().offsetHeight + 20 > scrollArea.offsetHeight) {
            //scroll down to selected row  
            scrollArea.scrollTop = scrollArea.scrollTop + ((row.get_element().offsetTop - scrollArea.scrollTop) +
            row.get_element().offsetHeight - scrollArea.offsetHeight) + row.get_element().offsetHeight;
        }
        //if the position of the the selected row is above the viewable grid area  
        else if ((row.get_element().offsetTop - scrollArea.scrollTop) < 0) {
            //scroll the selected row to the top  
            scrollArea.scrollTop = row.get_element().offsetTop;
        }
    }
}

注意:该功能不适用于页面回发。您应该直接从 javascript 触发(我注意到在 Telerik 示例中未触发网格的 ongridcreated 事件)。因此,更好的方法是使用 JQuery 处理滚动,如下所示:

1) 为特定网格创建函数

2) 在 Telerik 代码中,将发件人替换为 var sender = $find("<%= RadGrid1.ClientID%>");

3) $(window).load(function () {函数滚动网格();});

于 2014-03-04T13:34:23.343 回答