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

select row and paging

5 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Informat
Top achievements
Rank 1
Informat asked on 24 Jun 2010, 08:13 AM

Dear,

 

I am trying to server-side select a row in a radgrid which is using paging.

In the radgrid prerender I set a griddataitem.selected = true.

This works fine as long as the selected item gets displayed on the current displayed page.

How can i make the radgrid display the page that contains the selected item ?

 

Kind regards,

N.

 

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2010, 10:21 AM
Hello,


I guess you want to persist the selection when on paging. If so, you will find the online documentation as a helpful one.
Persisting the selected rows server-side on sorting/paging/filtering/grouping


-Shinu.
0
Informat
Top achievements
Rank 1
answered on 25 Jun 2010, 12:40 PM

Dear,

 

The thing is that during postback the selection of the grid must be changed at server side.

 

Kind regards,

N.

0
Martin
Telerik team
answered on 01 Jul 2010, 07:06 AM
Hello Informat,

I have already addressed the support ticket you have opened on the same topic. For the sake of keeping the support history trackable, let's continue this conversation in the forum thread only. Here is my post from the support ticket:

"Please note that when paging is enabled RadGrid fetches only the data that is required for the items of the currently displayed page. That is why the control does not persist user selection when the displayed page changes. The following help article demonstrates how to work around this behavior:

Persisting the selected rows server-side on sorting/paging/filtering/grouping

An approach similar to the one described in the help topic should be implemented in order to persist the index of the page that has the selected item. Once you know the page index, you can use RadGrid / GridTableView CurrentPageIndex property to navigate to it (you would need to rebind the grid if you set the CurrentPageIndex after the grid is already bound). However note that your "page index persisting" logic should take into account features like sorting or filtering which can cause one item to be contained in a different page when the grid is sorted / filtered."


I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mike Hobbs
Top achievements
Rank 1
answered on 13 Jul 2010, 06:12 PM
I've made this work outside of the PreRender event of the grid.  I created an event that is called after I bind the data to the grid.  My event looks like:

private void LoadCurrentItemSelections()
    {
        List<int> lstSelection = new List<int>();
        lstSelection = CurrentItemSelected;
        if ((lstSelection != null)
            && (lstSelection.Count > 0)
            && (rgrAssetList.Items.Count > 0))
        {
            if (CurrentPageIndex > 0)
            {
                rgrAssetList.CurrentPageIndex = CurrentPageIndex;
                rgrAssetList.Rebind();
            }
            foreach (int iAssetID in lstSelection)
            {
                try
                {
                    Telerik.Web.UI.GridDataItem gi =
                        rgrAssetList.MasterTableView.FindItemByKeyValue("AssetId", iAssetID);

                    if (gi != null)
                    {
                        gi.Selected = true;
                        gi.Focus();
                        //rgrAssetList.Rebind();
                    }
                }
                catch { }
            }
        }
    }



It handles changing the page index if needed also above.  It works well in normal aspx pages, but I'm currently having a problem when it's embedded deeper and the scroll bar.  I have a page size of 50 per page and the grid height is currently only large enough to show about 12 records at a time.  The scroll bar is used to scroll within a page only.  When I select an item lower than the top 12 visible in above procedure the scroll bar stays at the top.  If I scroll down I can see my item is selected.  If I press "tab" key the scroll bar moves to the row selected.

This seems to be a problem when the grid is embedded.  This is the structure:

Grid in User Control -> on APSX page -> opened into a RadWindow.

I tried placing this code in the PreRender already and it doesn't resolve.  I have this same logic working correctly on other pages in which the RadGrid isn't embedded to this level (it exists directly on ASPX page and not opened by RadWindow).

Anyone else having this problem?  More importantly does anyone have a solution?

Thank-you,

Mike
0
Martin
Telerik team
answered on 19 Jul 2010, 07:39 AM
Hello Mike Hobbs,

I would suggest that you open a formal support ticket and send me a stripped runnable demo that I could debug locally. This way I would be able to draw a clear picture of your scenario and provide you with more to-the-point resolution.

Regards,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Informat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Informat
Top achievements
Rank 1
Martin
Telerik team
Mike Hobbs
Top achievements
Rank 1
Share this question
or