0

EditForm モードですべての行を含む RadGrid があります。この Radgrid には仮想スクロールがあります。特定の行にジャンプ (スクロール) する必要があります。

いくつかのオプションを試しました。この場合、選択に行を入れることは適用されません。私は今試しました:

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. 

次の例は、この手法を示しています。

<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 () { thefunctiontoscrollthegrid();});

于 2014-03-04T13:34:23.343 に答える