This is a migrated thread and some comments may be shown as answers.

Scroll to EditForm

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 14 May 2012, 10:59 AM
Hello,

I use the Grid with EditFormType = Template. When the user clicks the edit button on an item which is at the bottom of the browser window, only the top of the editform is visible and the user has to scroll down to see the whole control. Is it possible to automatically scroll down so the form is completely visible?
Is there any built-in mechanism in the RadGrid?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 14 May 2012, 02:14 PM
Hello JP,

Sorry but there is not such type of functionality in it.

You must have to do this thing manually.

Let me know if you have any concern.

Thanks,
Jayesh Goyani
0
JP
Top achievements
Rank 1
answered on 14 May 2012, 03:13 PM
Ok, good to know. For everyone who has also to solve this problem, here is the solution:

In the GridItemDataBound event check if it is the edit mode and register client script block:
private void GridItemDataBound(object sender, GridItemEventArgs e)
      {
         if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
         {
            GridEditFormItem item = e.Item as GridEditFormItem;
            bool insert = item is GridEditFormInsertItem;
            Control control = item.FindControl("Editor");
            if (!insert)
            {
               ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "scroll", "scrollToElement('" + control.ClientID + "')", true);
            }
         }
      }

This is the javascript function you need to add:
function scrollToElement(id) {
   $('html, body').animate({
      scrollTop: $("#" + id).offset().top
   }, 1000);
}

Tags
Grid
Asked by
JP
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
JP
Top achievements
Rank 1
Share this question
or