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

GetSelectedItems only returns current page

7 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
golddog
Top achievements
Rank 1
golddog asked on 10 Aug 2011, 05:13 PM
We have a pretty simple grid, selected by a GridClientSelectColumn in each row.  We noticed the other day that if we selected, paged, then paged back, we lost the selection.

Implemented the client-side persistence as shown here, works great!

However, the grid only lets us have access to the current page's selections through grid.MasterTableView.GetSelectedItems on the server side when updating.  I also tried testing with grid.get_selectedItems() on the client, still only got the current page's selections.

Obviously, we want our users to be able to page through the options and then hit the submit button only once to save, instead of having to save on each page of the grid.

What am I missing to get the universe of selections from the grid instead of only the current page's selections?

Thank you,

Scott

7 Answers, 1 is accepted

Sort by
0
golddog
Top achievements
Rank 1
answered on 12 Aug 2011, 08:06 PM
Just in case anybody else needs to solve this, I stumbled around and got something.  Not saying it's great, but here's the basics.

On each page, or the submit button itself, we (on the server in code-behind) grab the selected items and store them into a form variable (just a comma-separated list of guids, which we obtain by using GetDataKeyValue("uniqueID") from each GridDataItem).  Then if it's a submit, we return that list from the RadWindow (in which our grid is located) to the main window, who then performs the update.

Don't forget, you'll want the update the hidden field through ajax when the grid is updated to persist the changes you make in the paging event handler on the client side.

Some details if anyone's interested:

RadGrid has a PageIndexChanged event to which you can subscribe.  Despite the past tense of the event, at the time the event fires, MasterTableView is exposing the "page from" selected items.  So, you can iterate over those to build your list.

Upon the submit button being hit, we iterate first to grab any that might be selected on the current page.

The trickiest part was tweaking the client-side RowDeselected event handler to grab our form element (with Document.getElementById) and parse it to see if we'd already saved the one being turned off and keep the others.  I only say that's tricky because I'm not the greatest javascript writer, and it took me a few tries to get it right.

I'm sure there's a better way I'm missing.  I probably could have taken advantage of the array we created in the client-side persistence.  But, this is what I thought of, and it seems to be working in IE9, FF, Chrome, and Safari, so it's good enough for now.

Remember, it's just software--we can always improve it later.
0
Iana Tsolova
Telerik team
answered on 16 Aug 2011, 02:31 PM
Hello Golddog,

Indeed, the grid creates and holds between postbacks only the items on the current page. However I can confirm that the approach you took to get the issue solved is right.
Additionally, I will forward the case to our support team, so they can add a code library with a runnable sample illustrating the approach.

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
golddog
Top achievements
Rank 1
answered on 16 Aug 2011, 05:16 PM
Thanks, Iana.  Let me suggest that this gets forwarded to the developers for future consideration:

If ClientDataKeys is specified, the grid itself should be able to do all the things I had to do myself.  Seems to me as if this should be included as part of the grid's functionality.
0
Iana Tsolova
Telerik team
answered on 17 Aug 2011, 10:18 AM
Hello Golddog,

I will forward this request for consideration as well.
However having such functionality is a bit in contrast with the fact that the grid has and is aware only of the items on the current page. In addition, this will affect the grid performance and will not work with custom paging.

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
golddog
Top achievements
Rank 1
answered on 17 Aug 2011, 03:03 PM
Ah, good point on the custom paging.  Maybe the development could go along the lines of, "using standard paging and client-side keys allows for out-of-the-box persistence of selected rows, but results in performance issues."

I'm sure there's a bunch of other ways this "problem" could be handled too; the implementor could probably catch some paging event and disallow paging if there's an unsaved state on the current page, etc, etc.
0
Carla
Top achievements
Rank 1
answered on 21 Mar 2014, 02:17 PM
Did this issue ever get resolved in the newer versions?  We are using custom paging and while I can capture the checked and selected items when the current page is exited and a new page is selected, I need the items to remained checked on all pages in case my customer goes back to that page before finally exiting the screen with the "done selecting items" button.  Currently the selected items get "unchecked" when the page is exited.

I need all the checked items to remain checked when they are paging through the pages
0
Pavlina
Telerik team
answered on 26 Mar 2014, 12:37 PM
Hello Carla,

Generally RadGrid loses its current selection when the current page changes. This also happens when the data is sorted or a new group or filter is added. If you want the selection to persist across these events, you can implement the server-side or client-side (depending on your scenario) approach presented in the following articles:
Persisting the Selected Rows Server-side
Persisting the Selected Rows Client-side

Give them a try and let me know if you need additional assistance.

Regards,
Pavlina
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Grid
Asked by
golddog
Top achievements
Rank 1
Answers by
golddog
Top achievements
Rank 1
Iana Tsolova
Telerik team
Carla
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or