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

[Solved] Save client side changes before/after NeedDataSource event?

4 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 25 Mar 2013, 07:07 PM
I'm trying to have a radgrid that uses the needdatasource event to allow filtering/sorting, but how do I keep client side changes made to the grid in between loads?

For example, the page loads, then a user clicks a button which changes the selected row on the client side. The user then sorts/filters and the changes are gone. I would like those changes to be preserved. The changes are actually committed to the server on another button click. Is this possible?

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 26 Mar 2013, 04:23 AM
Hi,

RadGrid loses its current selection when the data is sorted, a new group or filter is added, or when the current page changes. If you want the client-side selection to persist across these events, you can do the approach mentioned in the following help article.
Persisting the Selected Rows Client-side on Sorting/Paging/Filtering/Grouping

Thanks,
Shinu
0
Shawn
Top achievements
Rank 1
answered on 26 Mar 2013, 12:10 PM
Thanks, does NeedDataSource not perform a postback? Wouldn't the javascript array get wiped out or is there something I'm missing?
0
Shinu
Top achievements
Rank 2
answered on 27 Mar 2013, 06:33 AM
Hi,

NeedDataSource event performs a postback. In order to persist the client-side selection across these events, you can do the following:
  1. Define an empty javascript array for storage of the selected item's key values.

  2. Intercept the OnRowSelected and OnRowDeselected client events of the grid to save/remove the key value for the selected/deselected item respectively.

  3. Wire the OnRowCreated client event to mark the item which is about to be created as selected based on whether its key value is present in the javascript array.

Thanks,
Shinu
0
Shawn
Top achievements
Rank 1
answered on 27 Mar 2013, 02:00 PM
How does the javascript array store the values across the postback?

Edit: Nvm, I wasn't using a AjaxManager. Now that solution works perfectly. Thanks for your help.
Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Shawn
Top achievements
Rank 1
Share this question
or