1

I´m using GWT 2.4 with a DataGrid and a SimplePager along with a MultiSelectionModel. I want to implement a simple select-all-feature over all pages.

I´m only able to select all visible items on the current page. What is the best way to select all items on all pages?

I know the MultiSelectionModel stores the proxy keys provided by a ProvidesKey object in a HashMap. I think I have to request all proxy objects from server or at least all keys. But actually I don´t want to store information about the ProvidesKey´s getKey()-method on server-side. But I also can not access the MultiSelectionModel´s HashMap of the selected proxies´ keys. This all looks cumbersome, so is there a better way to solve this?

Tony Skulk
  • 237
  • 1
  • 3
  • 11
  • Can you update you question with relevant code snippets. It is not exactly clear why you are trying to deal with getKey or ProvidesKey. – appbootup Dec 04 '12 at 15:04

3 Answers3

0

Why do you need all keys for select all? When you select some objects from a list, you need to remember which ones are selected, but when you select all objects, you need a single Boolean:

// on click Select All button/checkbox
boolean selectAll = true;
// ask a user what he wants to do
// send a request to server with a parameter selectAll to update/delete all objects
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Thanks for your answer. That was my first approach. But after setting the selectAll flag I did not know how to handle any further changes without reasonable effort. I think the point I is to keep track of the negative selections when implementing my own `SelectionModel` as mentioned in Chris Lercher´s post. – Tony Skulk Dec 05 '12 at 09:41
0

As mentioned in https://developers.google.com/web-toolkit/doc/latest/DevGuideUiCellWidgets#selection, one way to achieve this would be to implement your own SelectionModel (e.g. by extending AbstractSelectionModel or DefaultSelectionModel):

A complex implementation can handle "select all" across multiple pages using a boolean to indicate that everything is selected, and then keep track of negative selections.

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • Thanks for your answer. I think keeping track of the negative selections is a good approach. I will try to implement my own `SelectionModel`. – Tony Skulk Dec 05 '12 at 09:45
0

Select all across multiple pages will work only if you are NOT lazy loading. First of all why do you need to select all? If you want to do some actions on all the grid data, you will already have the list and you can perform your actions on the list directly. Nonetheless you can select all the rows of the grid over multiple pages by iterating through the list and using the following API on each item.

 public void setSelected(T item, boolean selected);

Note: This will work only if you are NOT lazy loading.

Abhijith Nagaraja
  • 3,370
  • 6
  • 27
  • 55
  • Thanks for you answer. I need to select all and remove some items from the selected set afterwards. So I can´t operate on the whole list directly. – Tony Skulk Dec 05 '12 at 09:47