开发者

Setting ListGrid selection in SmartGWT with method "selectRecords(Record 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.


Found this solution;

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜