我需要一种从数据网格表中获取所有选定行的方法。这是我的代码:
import java.util.Arrays;
import java.util.List;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimpleLayoutPanel;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel;
public class GWTDataGrid implements EntryPoint {
private static class Address {
private final String houseNumber;
private final String streetName;
private final String county;
private final String postCode;
private final String country;
public Address(String houseNumber, String streetName, String county, String postCode, String country) {
this.houseNumber = houseNumber;
this.streetName = streetName;
this.county = county;
this.postCode = postCode;
this.country = country;
}
}
/*
* The list of data to display.
*/
private static final List<Address> ADDRESS = Arrays.asList(
new Address("a1", "MG Road", "Bangalore", "560068", "India")
,new Address("a2", "AGC Bose Road ", "Kolkata", "700028", "India"));
@Override
public void onModuleLoad() {
DataGrid<Address> table = new DataGrid<Address>();
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
TextColumn<Address> houseNumber = new TextColumn<Address>() {
@Override
public String getValue(Address object) {
return object.houseNumber;
}
};
table.addColumn(houseNumber, "House Number");
TextColumn<Address> streetName = new TextColumn<Address>() {
@Override
public String getValue(Address object) {
return object.streetName;
}
};
table.addColumn(streetName, "Street Name");
TextColumn<Address> county = new TextColumn<Address>() {
@Override
public String getValue(Address object) {
return object.county;
}
};
table.addColumn(county, "Country");
TextColumn<Address> postCode = new TextColumn<Address>() {
@Override
public String getValue(Address object) {
return object.postCode;
}
};
table.addColumn(postCode, "Postal Code");
TextColumn<Address> country = new TextColumn<Address>() {
@Override
public String getValue(Address object) {
return object.country;
}
};
table.addColumn(country, "Country");
// Add a selection model to handle user selection.
final SelectionModel<Address> selectionModel = new MultiSelectionModel<Address>();
table.setSelectionModel(selectionModel);
/* selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
`**//WHAT TO DO INSIDE IN IT TO GET ALL THE SELECTED ROW's ITEM**`
}
}
});*/
table.setRowCount(ADDRESS.size(), true);
table.setRowData(0, ADDRESS);
table.setWidth("100%");
SimpleLayoutPanel slp = new SimpleLayoutPanel();
slp.add(table);
// Add it to the root panel.
RootLayoutPanel.get().add(slp);
}
}
如何存储所有那些被选中的行索引?我没有使用checkboxcell
。