2013-08-06 6 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

내가 바인딩 이벤트 뒤에 코드에서 항목을 선택하십시오. 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; 
     } 
    } 
} 

주의 :이 기능은 페이지 포스트 백에서 작동하지 않습니다

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. 

다음 예

이 기술을 보여줍니다. 당신은 자바 스크립트에서 직접 triger해야합니다 (나는 눈금의 ongridcreated 이벤트 Telerik 예제에서 해고되지 않습니다 통지). 그래서 더 나은 방법은 다음과 같이 jQuery로 스크롤을 처리하는 것입니다

1)이 telerik 코드에서 특정 그리드

2)에 대한 함수를 만듭니다 var에 보낸 사람과 보낸 사람을 대체 = $ "(<을 찾을 수 % = RadGrid1.ClientID %> ");

3) $ (window). (function() {function}}}}}}}}};

+0

이 링크가 질문에 대답 할 수 있지만 여기에 답변의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. –

+0

이 부분에 대해 잘 알고 있습니다 만, 대답은 공식 Telerik 가이드입니다. 그래서 그냥 복사 - 붙여 넣기 공식 페이지에서 대답은 내가 생각하는 최악이 될 것입니다. –

+0

복사 - 붙여 넣기가 조금 더 많을 수 있지만 인용해도 좋습니다. 우리는 심지어 그것에 대한 가격 인하 (인용 된 텍스트 앞의 ">")도 있습니다. 또한 스택 오버플로를 환영합니다! –