ข้ามไปที่แถวใน RadGrid

ฉันมี RadGrid พร้อมทุกแถวในโหมด EditForm Radgrid นี้มีการเลื่อนเสมือนจริง ฉันต้องข้าม (เลื่อน) ไปยังแถวที่ต้องการ

ฉันลองหลายตัวเลือกแล้ว ในกรณีนี้การใส่แถวในการเลือกจะไม่สามารถใช้ได้ ตอนนี้ฉันได้ลองแล้ว:

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

ใน ItemDataBound แต่:

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

ดูเหมือนจะไม่ทำงาน

มีความคิดใดบ้างเกี่ยวกับวิธีแก้ไขปัญหานี้ให้ดีที่สุด?


person Peter Huisman 75    schedule 06.08.2013    source แหล่งที่มา


คำตอบ (1)


ลอง เลื่อนไปที่รายการที่เลือก

ฉันเลือกรายการในโค้ดด้านหลังในเหตุการณ์ databound

   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;
        }
    }
}

Notice : The function does not work on page postbacks. you should triger directly from javascript (i notice that the ongridcreated event of the grid is not fired on the Telerik example). So a better way is to handle the scrolling with JQuery like this :

1) สร้างฟังก์ชันสำหรับกริดเฉพาะ

2) ที่โค้ด telerik ให้แทนที่ผู้ส่งด้วย var sender = $find("‹%= RadGrid1.ClientID%>");

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

person Zisis Stylianos    schedule 04.03.2014
comment
แม้ว่าลิงก์นี้อาจตอบคำถามได้ แต่ควรรวมส่วนสำคัญของคำตอบไว้ที่นี่และเตรียมลิงก์ไว้เพื่อใช้อ้างอิงด้วย คำตอบสำหรับลิงก์เท่านั้นอาจใช้ไม่ได้หากหน้าที่เชื่อมโยงมีการเปลี่ยนแปลง - person S.L. Barth; 04.03.2014
comment
คุณมีสิทธิ์ในส่วนนี้ แต่คำตอบคือ Telerik Guide อย่างเป็นทางการ ฉันคิดว่าแค่คัดลอก-วางคำตอบจากหน้าอย่างเป็นทางการคงแย่ที่สุด - person Zisis Stylianos; 04.03.2014
comment
การคัดลอกและวางอาจจะมากสักหน่อย แต่ก็สามารถอ้างอิงได้ เรายังมีมาร์กดาวน์สำหรับสิ่งนั้นด้วย (the › หน้าข้อความที่ยกมา) นอกจากนี้ - ยินดีต้อนรับสู่ Stack Overflow! - person S.L. Barth; 04.03.2014