当我点击DatePickerCell的单元格时,表格选择不再有效。
下表只有2列:日期,文字
使用GWT测试的是2.4和2.5 使用Chrome,IE9进行测试
发布的代码有问题吗?
是否有一个带有SelectionModel和DateCellPicker的DataGrid工作示例的链接,该选择是否正常?
一个有效的例子可以回答我的问题。
更新
我发布了一个完整的可运行示例。
import com.google.gwt.cell.client.DatePickerCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class DataGridCss implements EntryPoint
{
/**
* A simple data type that represents a contact.
*/
private static class Contact
{
private final String address;
private Date birthday;
private final String name;
public Contact(String name, Date birthday, String address)
{
this.name = name;
this.birthday = birthday;
this.address = address;
}
}
/**
* The list of data to display.
*/
private static final List<Contact> CONTACTS = Arrays.asList(new Contact("John", new Date(), "123 Fourth Avenue"), new Contact("Joe", new Date(), "22 Lance Ln"), new Contact("George", new Date(),"1600 Pennsylvania Avenue"));
public void onModuleLoad()
{
final DataGrid<Contact> table = new DataGrid<Contact>(100);
table.setSize("700px", "300px");
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
// Add a date column to show the birthday.
DatePickerCell dateCell = new DatePickerCell();
Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell)
{
@Override
public Date getValue(Contact object)
{
return object.birthday;
}
};
// Add a field updater to be notified when the user enters a new name.
dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>()
{
@Override
public void update(int index, Contact object, Date value)
{
object.birthday = value;
}
});
table.addColumn(dateColumn, new TextHeader("Birthday"));
TextColumn<Contact> addressColumn = new TextColumn<Contact>()
{
@Override
public String getValue(Contact object)
{
return object.address;
}
};
table.addColumn(addressColumn, new TextHeader("Address"));
// Add a selection model to handle user selection.
final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
table.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler()
{
public void onSelectionChange(SelectionChangeEvent event)
{
Contact selected = selectionModel.getSelectedObject();
if (selected != null)
{
Window.alert("You selected: " + selected.name);
}
}
});
table.setRowCount(CONTACTS.size(), true);
table.setRowData(0, CONTACTS);
RootPanel.get().add(table);
}
}
答案 0 :(得分:1)
从AbstractCellTable的源代码看起来,您必须使用KeyboardSelectionPolicy.BOUND_TO_SELECTION或提供至少一个处理选择的单元格类型。
向Google提交了一份错误报告:
http://code.google.com/p/google-web-toolkit/issues/detail?id=8064