CellTable - Adding a Button to a Column

5,850 views
Skip to first unread message

dave_mcgee

unread,
Oct 28, 2010, 5:26:23 AM10/28/10
to Google Web Toolkit
Hi there,

I'm wondering if anyone could assist me with adding buttons to columns
within CellTables? I can do TextColumns fine but I'm experiencing
issues adding a button I've defined. So its been working fine with the
text using the code at the end.. but i want to do this:

// create a column for a download button
// add the button to the column
// add the column to the table


Any ideas much apreciated!
--

(This works fine for text..)

documentColumn = new TextColumn<DocumentDetailsDTO>() {
@Override
public String getValue(DocumentDetailsDTO object) {
return object.getName();
}
};

table.addColumn(documentColumn, "File");

Regards,
Dave.

John LaBanca

unread,
Oct 28, 2010, 11:05:42 AM10/28/10
to google-we...@googlegroups.com
You can create a Column with a ButtonCell as follows:
ButtonCell buttonCell = new ButtonCell();
Column buttonColumn = new Column<DocumentDetailsDTO, String>(buttonCell) {
  @Override
  public String getValue(DocumentDetailsDTO object) {
    // The value to display in the button.
    return object.getName();
  }
}
table.addColumn(buttonColumn, "Action");

You can then set a FieldUpdater on the Column to be notified of clicks.
buttonColumn.setFieldUpdater(new FieldUpdater<DocumentDetailsDTO, String>() {
  public void update(int index, DocumentDetailsDTO object, String value) {
    // Value is the button value.  Object is the row object.
    Window.alert("You clicked: " + value);
  }
});

Thanks,
John LaBanca
jlab...@google.com



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


dave_mcgee

unread,
Nov 2, 2010, 7:05:20 AM11/2/10
to Google Web Toolkit
Thanks John, that worked nicely!

Much apreciated!

Regards,
Dave.


On Oct 28, 8:05 am, John LaBanca <jlaba...@google.com> wrote:
> You can create a Column with a ButtonCell as follows:
> ButtonCell buttonCell = new ButtonCell();
> Column buttonColumn = new Column<DocumentDetailsDTO, String>(buttonCell) {
>   @Override
>   public String getValue(DocumentDetailsDTO object) {
>     // The value to display in the button.
>     return object.getName();
>   }}
>
> table.addColumn(buttonColumn, "Action");
>
> You can then set a FieldUpdater on the Column to be notified of clicks.
> buttonColumn.setFieldUpdater(new FieldUpdater<DocumentDetailsDTO, String>()
> {
>   public void update(int index, DocumentDetailsDTO object, String value) {
>     // Value is the button value.  Object is the row object.
>     Window.alert("You clicked: " + value);
>   }
>
> });
>
> Thanks,
> John LaBanca
> jlaba...@google.com
>
> On Thu, Oct 28, 2010 at 5:26 AM, dave_mcgee <daveomc...@gmail.com> wrote:
> > Hi there,
>
> > I'm wondering if anyone could assist me with adding buttons to columns
> > within CellTables? I can do TextColumns fine but I'm experiencing
> > issues adding a button I've defined. So its been working fine with the
> > text using the code at the end.. but i want to do this:
>
> > // create a column for a download button
> > // add the button to the column
> > // add the column to the table
>
> > Any ideas much apreciated!
> > --
>
> > (This works fine for text..)
>
> >        documentColumn = new TextColumn<DocumentDetailsDTO>() {
> >            @Override
> >            public String getValue(DocumentDetailsDTO object) {
> >                return object.getName();
> >            }
> >        };
>
> >      table.addColumn(documentColumn, "File");
>
> > Regards,
> > Dave.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>
> > .

Ariel Cessario

unread,
Jun 18, 2013, 1:36:11 PM6/18/13
to google-we...@googlegroups.com, jlab...@google.com
I was strugling with this for a long while.

Thanks john, it worked great!

Regards
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages