在 SmartGWT 中设置 ListGrid 选择

发布于 2024-10-20 06:29:57 字数 209 浏览 0 评论 0原文

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

I'm trying to set the selected records of a ListGrid table object in SmartGWT, but I can't find any way of doing it. I know there's a getSelectedRecords() function, but no matching setSelectedRecords(). I tried to see if set/getSelectedState() would work, but GWT complains about needing a primary key and a DataSource object. Is there any way to set the selection of a ListGrid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光是把杀猪刀 2024-10-27 06:29:57

为此,您可以使用 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;
}

For this you can use one of the selectRecords() methods, like so:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文