2013-08-06 50 views
0

我在EditForm模式下的所有行都有一個RadGrid。這個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); }

似乎並沒有工作。

關於如何最好地解決這個問題的任何想法?

回答

1

試試這個Scrolling to the Selected Item

我在代碼中的數據綁定事件背後選擇的項目。

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(我注意到網格的ongridcreated事件沒有在Telerik例子中觸發)觸發。 所以更好的辦法是處理與jQuery滾動這樣的:

1)爲特定的網格

2)在Telerik的代碼創建一個函數替換使用var發件人發送= $找到(」 < %= RadGrid1.ClientID%>「); ()函數(){ thefunctiontoscrollthegrid();});

+0

儘管此鏈接可能會回答問題,但最好在此處包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 –

+0

那麼你在這一部分有權利,但答案是官方Telerik指南。所以只是從官方網頁複製粘貼答案將是我認爲最糟糕的。 –

+0

複製粘貼可能有點多,但可以引用。我們甚至會爲此減價(在引用文字前的「>」)。另外 - 歡迎來到堆棧溢出! –