2011-03-06 57 views
4

我想在SmartGWT中設置ListGrid表格對象的選定記錄,但是我找不到任何方法。我知道有一個getSelectedRecords()函數,但沒有匹配的setSelectedRecords()。我試圖看看set/getSelectedState()是否可以工作,但GWT抱怨需要一個主鍵和一個DataSource對象。有什麼辦法可以設置ListGrid的選擇嗎?在SmartGWT中設置ListGrid選擇

回答

4

爲此,您可以使用的selectRecords()方法之一,比如:

public void onModuleLoad() 
{ 
    VLayout main = new VLayout(); 
    final ListGrid grid = new ListGrid(); 
    grid.setHeight(500); 
    grid.setWidth(400); 
    grid.setFields(new ListGridField("name", "Name")); 
    grid.setData(createRecords()); 

    final IButton button = new IButton("Select some"); 
    button.addClickHandler(new ClickHandler() { 
     public void onClick(ClickEvent event) 
     { 
      grid.selectRecords(new int[]{2, 3}); //This will select index 2 and 3 
     } 
    }); 

    main.addMember(grid); 
    main.addMember(button); 
    RootPanel.get().add(main); 
} 

private ListGridRecord[] createRecords() 
{ 
    return new ListGridRecord[]{ 
     createRecord("monkey"), 
     createRecord("banana"), 
     createRecord("orange"), 
     createRecord("sun") 
    }; 
} 

private ListGridRecord createRecord(String name) 
{ 
    ListGridRecord record = new ListGridRecord(); 
    record.setAttribute("name", name); 
    return record; 
} 
+1

唉。爲什麼看起來他們隱藏了我的功能?謝謝。 – therin 2011-03-07 00:53:16

+0

@therin我知道這種感覺,這些界面真的很臃腫和不一致。很高興我能幫上忙。 – 2011-03-07 08:09:02