2011-03-06 61 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