0

当我单击一个为 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);
    }
}
4

1 回答 1

1

从 AbstractCellTable 的源代码看起来,您确实必须使用 KeyboardSelectionPolicy.BOUND_TO_SELECTION 或提供至少一种处理选择的单元格类型。

向 Google 提交了错误报告:

http://code.google.com/p/google-web-toolkit/issues/detail?id=8064

于 2013-03-07T17:02:13.297 回答