2012-07-23 92 views

回答

2

問題的標題不能反映內部

有隻選擇行的單元格的任何方式的實際問題?

號一個Vaadin表的整點是反映行以表格形式數據的。表設置爲可選跟蹤選定行的itemIds與表

可能能夠由表中使用ColumnGenerator,並添加監聽到生成組件模擬選擇單元格。然而,移除監聽器可能會很棘手。

或者,您可能希望簡單地生成GridLayout中的組件並自行跟蹤所選單元格。

最終,這裏的方法實際上取決於你想要達到的目標。

+0

謝謝你的回答。我搜索ColumnGenerator並編寫了代碼,但它不起作用。我試圖做一個表(7X24),當我點擊一個單元格時,該行中的其他單元格將不會被選中。如果你能給我一個簡短的例子,我會很高興。 – Hasan 2012-07-23 13:17:30

+0

@Hasan:你有沒有試過讓表setSelectable(false)? – 2012-07-23 13:32:57

+0

不,我沒有。代碼在這裏http://www.manashk.com/java/。程序只創建表並不加載內容。 – Hasan 2012-07-23 13:55:31

1

這取決於你想要完成什麼。 (您的問題標題和您的問題細節解決了兩個不同的問題。)如果您想知道您是否可以定位特定單元格併爲其添加點擊監聽器,那麼當然可以:

//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); 

檢查the documentation可能是有益的。

相關問題