2

vaadinで複数選択可能なテーブルを作成しましたが、クリックするとすべての行が選択されるため、このテーブルのセルだけを選択することはできません。

行のセルのみを選択する方法はありますか?

4

2 に答える 2

2

The title of the question doesn't reflect the actual question inside

Is there any way of selecting only a cell of a row ?

No. The whole point of a Vaadin table is to reflect rows of data in a tabular form. Setting a table to selectable keeps track of the itemIds of the selected rows with the table

You might be able to simulate selecting cells by using a ColumnGenerator in the table, and adding a listener to the generated component. Removing the listener may be tricky, however.

Alternatively, you may wish to simply generate components in a GridLayout and keep track of the selected cells yourself.

Ultimately, the approach here really depends upon exacly what you are trying to achieve.

于 2012-07-23T11:37:11.343 に答える
1

それはあなたが達成しようとしていることに依存します。(質問のタイトルと質問の詳細は、2 つの異なる質問に対応しています。) 特定のセルをターゲットにしてクリック リスナーを追加できるかどうか疑問に思っている場合は、もちろん、次のこともできます。

//initial layout setup
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);

//Create a table and add a style to allow setting the row height in theme.
final Table table = new Table();
table.addStyleName("components-inside");

//Define the names and data types of columns.
//The "default value" parameter is meaningless here.
table.addContainerProperty("Sum",            Label.class,     null);
table.addContainerProperty("Is Transferred", CheckBox.class,  null);
table.addContainerProperty("Comments",       TextField.class, null);
table.addContainerProperty("Details",        Button.class,    null);

//Add a few items in the table.
for (int i=0; i<100; i++) {
    // Create the fields for the current table row
    Label sumField = new Label(String.format(
                   "Sum is <b>$%04.2f</b><br/><i>(VAT incl.)</i>",
                   new Object[] {new Double(Math.random()*1000)}),
                               Label.CONTENT_XHTML);
    CheckBox transferredField = new CheckBox("is transferred");

    //Multiline text field. This required modifying the 
    //height of the table row.
    TextField commentsField = new TextField();
    //commentsField.setRows(3);

    //The Table item identifier for the row.
    Integer itemId = new Integer(i);

    //Create a button and handle its click. A Button does not
    //know the item it is contained in, so we have to store the
    //item ID as user-defined data.
    Button detailsField = new Button("show details");
    detailsField.setData(itemId);
    detailsField.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            // Get the item identifier from the user-defined data.
            Integer iid = (Integer)event.getButton().getData();
            Notification.show("Link " +
                              iid.intValue() + " clicked.");
        } 
    });
    detailsField.addStyleName("link");

    //Create the table row.
    table.addItem(new Object[] {sumField, transferredField,
                                commentsField, detailsField},
                  itemId);
}

//Show just three rows because they are so high.
table.setPageLength(3);

layout.addComponent(table);

ドキュメントを調べることは有益かもしれません。

于 2013-07-11T17:50:14.097 に答える