How to add checkbox in header.

1,654 views
Skip to first unread message

Diyko

unread,
Dec 14, 2010, 2:17:35 PM12/14/10
to Google Web Toolkit
I need add checkbox in header and implement "check/uncheck all rows"
functionality?
Anybody did it already?

Diyko

unread,
Dec 15, 2010, 2:30:48 AM12/15/10
to Google Web Toolkit
I thought it should be easy
Help

Subhrajyoti Moitra

unread,
Dec 15, 2010, 10:03:34 AM12/15/10
to google-we...@googlegroups.com
I believe u are talking about CellTable widget. If so..

Define a Header object;
Implement the getValue method.

The header accepts a cell object in its constructor.
U can define any Cell like CheckBoxCell etc.

CheckboxCell cb=new CheckboxCell();
Header<Boolean> hdr=new Header<Boolean>(cb) {
                    @Override
                    public Boolean getValue() {
                       
                        return false;//return true to see a checked checkbox.
                    }
                };

CellTable ct=new CellTable();
ct.addColumn(colCell,hdr);

colCell is defined elsewhere.

Hope this helps.

Thanks,
Subhro.


--
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.


Subhrajyoti Moitra

unread,
Dec 15, 2010, 10:05:39 AM12/15/10
to google-we...@googlegroups.com
""check/uncheck all rows""- For this, u will either extend CheckBoxCell and override the onBrowserEvent(....) method.
or create a new AbstractCell and override the onBrowser(..) method..

Thanks,
Subhro.

2010/12/15 Subhrajyoti Moitra <subhra...@gmail.com>

Dominik

unread,
Dec 15, 2010, 10:33:55 AM12/15/10
to Google Web Toolkit
Hi,
what do you want to do,
do you want to have a CheckBox in every row to select the row and a
selectbox in the header to select every row at once or
do just want to select every row without the ability to select a
single row?

John LaBanca

unread,
Dec 15, 2010, 1:41:49 PM12/15/10
to google-we...@googlegroups.com
Create a CheckboxCell that handles selection and put it into the header like subhrajyotim suggested.  Call Header#setUpdater(ValueUpdater) to handle events when the checkbox is clicked.

You'll probably want to use a DefaultSelectionModel, which supports selecting rows by default, then adding exceptions to the rule.

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


Diyko

unread,
Dec 17, 2010, 4:07:22 AM12/17/10
to Google Web Toolkit
Yep
I want implement checkbox multiselection in table
With checkbox in header

Jerome C.

unread,
Dec 17, 2010, 4:31:36 AM12/17/10
to google-we...@googlegroups.com
Here is my code for that (Message is my model object, but it can be all you want) :

Column<Message, Boolean> select = new Column<Message, Boolean>(new CheckboxCell(true)) {


@Override

public Boolean getValue(Message object)

{

return selectionModel.isSelected(object);

}

};

select.setFieldUpdater(new FieldUpdater<Message, Boolean>() {

public void update(int index, Message object, Boolean value)

{

// Called when the user clicks on a checkbox.

selectionModel.setSelected(object, value);

}

});


Header<Boolean> selectAllHeader = new Header<Boolean>(new CheckboxCell()) {


@Override

public Boolean getValue()

{

return selectionModel.getSelectedSet().size() == table.getRowCount();

}

};


selectAllHeader.setUpdater(new ValueUpdater<Boolean>() {


@Override

public void update(Boolean value)

{

List<Message> displayedItems = table.getDisplayedItems();


for (Message msg : displayedItems)

{

selectionModel.setSelected(msg, value);

}

}

});


table.addColumn(select, selectAllHeader);

Diyko

unread,
Dec 17, 2010, 10:40:55 AM12/17/10
to Google Web Toolkit
Thanks everybody
Merry X-mas

atul

unread,
Jun 8, 2011, 3:23:31 AM6/8/11
to Google-We...@googlegroups.com
Hello,

Thanks for showing how to add an checkbox in the celltable header.

I have another question in this regard.
I am showing this celltable data with checkbox header as above
as first column and
other columns as Name, Address, etc.
Also I am using SimplePager to show the data in celltable
in paginated format with pagesize 5.

Question:
The first 5 records are shown in first page and
when the uses clicks the
checkbox header cell all the first 5 records in the celltable are selected
alongwith the checkbox header cell itself.

On paging to next page by clicking the next page image(or icon) on the
SimplePager, the next 5 records from the celltable are shown
but the checkbox header cell remains selected (true)
as I had clicked it in the first page.

I need the checkbox header as unchecked again (false)
when the user clicks on the
next page and new records are shown.

SimplePager does on raise any event
on clickcing the next page image(or icon).

Please Help

Thanks and Regards,
atul gaikwad

Taha Hussain

unread,
Jul 27, 2011, 7:03:11 PM7/27/11
to Google-We...@googlegroups.com
atul <emailatulg@...> writes:


atul- I used the MyHeader class from
http://snipt.net/araujo921/checkbox-in-gwt-celltable-header/ and added one more
method to it:
public void setValue(int column, boolean value) {
this.value = value;
changeValue.changedValue(column, value);
}

for the celltable, add loading state change handler; this way you don't have to
worry about "what happens on sort (if you are doing server-side sorting)",
pagination etc.

table.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() {
@Override
public void onLoadingStateChanged(LoadingStateChangeEvent event) {
if (event.getLoadingState().equals(LoadingState.LOADING)) {
checkBoxHeader.setValue(false);
}
});

taha


Reply all
Reply to author
Forward
0 new messages