4

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?

1 Answer 1

4

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;
}
2
  • 1
    Ugh. Why does it seem like they are hiding functions from me? Thanks.
    – therin
    Mar 7, 2011 at 0:53
  • @therin I know the feeling, these interfaces are really bloated and inconsistent. Glad I could help.
    – Mia Clarke
    Mar 7, 2011 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.