3

On Telerik demo site we can see an example of how to implement kind of functionality: "check all checkbox in a grid's column". But in my case it has 2 disadvantages:

  1. It didn't check all checkbox on all pages.
  2. It didn't save a state of checkboxes on different pages.

Is anybody know how to resolve these issues? Thanks in advance.

apros
  • 2,848
  • 3
  • 27
  • 31

3 Answers3

1

I can't test this, so I'm not 100% sure, but looking at Telerik's example, one reason it's not persisted is because every "page" of the grid requires a postback, and in the controller action result method, they aren't passing in the model (or view model) for the items that are bound to the grid, they're only returning that list of items back to the view, so it will never "save" which items are checked/selected and which ones aren't. You should be able to get around this by making your view model a parameter into the HttpPost action result method and then passing that list back to the view after the post so that it retains which items are selected instead of creating a new one. This won't solve the issue with not selecting all the items, but it should at least retain which ones are selected throughout the pages. I think the reason for it not working with all items is it can only select the ones that are actually being displayed at the time. You may want to do a post (or ajax) to select "all" items.

Eric Garrison
  • 291
  • 1
  • 10
  • 21
1

As long as I know there's no built-in functionality to do so. The same problem happens when you select records on page one and change to page two, you loose whatever you selected before.

To achieve that functionality you have 2 options (I've used both on previous projects)

1) On each check make an Ajax call to one of your controllers and store whatever you selected on a Session Variable (This can be inefficient if you have a lot of records) 2) Create a javascript variable and store your selections there, and send back to the controller using a json variable or a comma separated values string

As I said, I've used both approachs so it depends on if this works for you or not

Hope it helps

pollirrata
  • 5,188
  • 2
  • 32
  • 50
1

One of the major reasons for using paging in grids is so that you don't have to retrieve all of the data from the data store and generate a lot of HTML to push to the client.

It's been my experience that most users understand that a "select all" check box only checks the items on the current page. I've not seen a site where checking such a check box would actually check all records, even those I can't see.

If you have an action which will affect more than the current page of records, I would suggest that you add a button which clearly indicates that the action will affect all records, then send a command to your data layer which will perform that action. This will perform better (you don't have to send a potentially long list of ids across the wire) and allow users to understand the repercussions of their action.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • Thanks for sharing your opinion. Unfortunately in my case users will uncheck something periodically. So, your solutions cannot fit needs of my customers. – apros Jul 14 '12 at 11:05