DataGrid GWT 2.4 RC1

941 views
Skip to first unread message

News Club

unread,
Aug 12, 2011, 8:54:24 PM8/12/11
to google-we...@googlegroups.com
Hi:

I want to try the DataGrid in 2.4 RC1 release. I took the CellTable example and slightly modified it to use DataGrid. I could compile fine but nothing gets displayed in the browser and no exceptions. I don't know why it is not working.

Appreciate your help. Thanks.

NR

public class DataGridExample implements EntryPoint {
  private static class Contact {
    private final String address;
    private final Date birthday;
    private final String name;

    public Contact(String name, Date birthday, String address) {
      this.name = name;
      this.birthday = birthday;
      this.address = address;
    }
  }

  private static final List<Contact> CONTACTS = Arrays.asList(
      new Contact("John", new Date(80, 4, 12), "123 Fourth Avenue"),
      new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln"),
      new Contact("George", new Date(46, 6, 6), "1600 Pennsylvania Avenue"));

  public void onModuleLoad() {
    DataGrid<Contact> table = new DataGrid<Contact>();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
      @Override
      public String getValue(Contact object) {
        return object.name;
      }
    };
    table.addColumn(nameColumn, "Name");

    DateCell dateCell = new DateCell();
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
      @Override
      public Date getValue(Contact object) {
        return object.birthday;
      }
    };
    table.addColumn(dateColumn, "Birthday");

    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
      @Override
      public String getValue(Contact object) {
        return object.address;
      }
    };
    table.addColumn(addressColumn, "Address");

    final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
      public void onSelectionChange(SelectionChangeEvent event) {
        Contact selected = selectionModel.getSelectedObject();
        if (selected != null) {
          Window.alert("You selected: " + selected.name);
        }
      }
    });

    table.setRowCount(CONTACTS.size(), true);

    table.setRowData(0, CONTACTS);

    RootPanel.get().add(table);
  }
}


Jeff Larsen

unread,
Aug 13, 2011, 12:43:08 PM8/13/11
to google-we...@googlegroups.com
I think DataGrid needs to be displayed inside a LayoutPanel. 

Foermchen82

unread,
Aug 14, 2011, 6:00:12 AM8/14/11
to Google Web Toolkit
I have tried it to add in on a LayoutPanel, but nothing is displayed.
what I have to do?

Rajesh

unread,
Aug 14, 2011, 12:06:15 PM8/14/11
to Google Web Toolkit
DataGrid provides scrolling capabilities. setHeight() on the table.

Foermchen82

unread,
Aug 14, 2011, 12:27:15 PM8/14/11
to Google Web Toolkit
How can I at a DataGrid to a panel next to other panel. The problem
is, that a LayoutPanel has to be added to the RootLayoutPanel. This is
allways in fullscreen. So how can I add, for example, a navigationbar
next to the DataGrid?

I tried the following, but it doesn't work:

DataGrid grid = new DataGrid();
DockPanel mainPanel = new DockPanel();
mainPanel.add(new Label("HeaderPanel"), DockPanel.NORTH);
mainPanel.add(new Label("Navigationbar"), DockPanel.WEST);
mainPanel.add(grid, DockPanel.CENTER);

RootLayoutPanel.get().add(mainPanel);

Jeff Larsen

unread,
Aug 15, 2011, 11:02:26 AM8/15/11
to google-we...@googlegroups.com

DockPanel mainPanel = new DockPanel(); 

DockPanel isn't a LayoutPanel. Try DockLayoutPanel. 

NR

unread,
Aug 15, 2011, 1:55:21 PM8/15/11
to Google Web Toolkit

Thank you all. Adding the DataGrid directly to a LayoutPanel works.

Ash

unread,
Oct 13, 2011, 8:58:18 AM10/13/11
to Google Web Toolkit
Hi All,

Did anyone managed to add a image to a cell that can be clicked (or a
button with image on it)??

I'm trying from last two days.. plz help.

Thanks,
-ash

Piro

unread,
Oct 13, 2011, 12:19:03 PM10/13/11
to Google Web Toolkit
Get inspired by ButtonCell source code. All you need is to set image
as css background. But css styles doesn't work. At least they didn't
use to. You have to create button with own css class name and define
background image for css class. Something like <button
class="cssClassWithBackgroundImage">.
Or use <img> tag and set hand cursor (through css class too).
Reply all
Reply to author
Forward
0 new messages