Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top