使用“selectRecords(Record record)”方法在 SmartGWT 中设置 ListGrid 选择

发布于 2024-10-26 02:33:35 字数 1166 浏览 1 评论 0原文

我正在尝试使用记录在 SmartGWT 中设置 ListGrid 表对象的选定记录,但我找不到任何方法。我想选择记录,而不是索引。我想使用 selectRecord(Record record) 方法。

举个例子;

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.selectRecord(createRecord("orange")); 
        }  
    });  

    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;
}

在本例中,我想选择橙色,但此代码选择任何内容。 有可能吗?如果可以的话怎么办?

提前致谢。

I'm trying to set the selected records of a ListGrid table object in SmartGWT using records, but I can't find any way of doing it. I want to select with record, not index. I want to use selectRecord(Record record) method.

As an example;

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.selectRecord(createRecord("orange")); 
        }  
    });  

    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;
}

In this case I want to select orange, But this code select anything.
Is it posible? If possible how?

Thanks in advance.

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

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

发布评论

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

评论(2

远昼 2024-11-02 02:33:35

找到了这个解决方案;

selectRecord(grid.getRecordList().find("name", "orange"));

Found this solution;

selectRecord(grid.getRecordList().find("name", "orange"));
手长情犹 2024-11-02 02:33:35

你的代码有问题:
当您编写

grid.selectRecord(record);

时,它会搜索网格具有的同一记录实例。如果记录的两个实例相等,则仅 &然后它选择记录。否则什么也不会发生,就像你现在所面临的那样。这里你需要做的是:

ListGridRecord[] records = countryGrid.getRecords();
int i;
for (i = 0; i < records.length; i++)
{
    if (records[i].getAttribute("name").equalsIgnoreCase("orange"))
    {
        break;
    }
}
countryGrid.selectRecord(i);

There's a problem with your code:
When you write

grid.selectRecord(record);

it goes to search the same record instance that the grid has. If both instances of record are equal, only then & then it selects the record. Otherwise nothing happens as you're facing right now. Here what you need to do is:

ListGridRecord[] records = countryGrid.getRecords();
int i;
for (i = 0; i < records.length; i++)
{
    if (records[i].getAttribute("name").equalsIgnoreCase("orange"))
    {
        break;
    }
}
countryGrid.selectRecord(i);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文