在SmartGWT中设置ListGrid选择

时间:2011-03-06 09:07:52

标签: gwt smartgwt

我正在尝试在SmartGWT中设置ListGrid表对象的选定记录,但我找不到任何方法。我知道有一个getSelectedRecords()函数,但没有匹配的setSelectedRecords()。我试图看看set / getSelectedState()是否可行,但GWT抱怨需要主键和DataSource对象。有没有办法设置ListGrid的选择?

1 个答案:

答案 0 :(得分: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;
}