GWT 2.1 CellTable Column Header click events

Is there a way to add clickHandlers (or any type of handler) to the column headers in CellTable ? I want to add some sorting functions to my CellTable, and I don't see any methods in the Column or Header classes that will allow this. I used this article to figure out how to use CellTable.

+8
java gwt
Jul 16 '10 at 5:28
source share
4 answers

There is no way to support sorting in CellTable. However, there is a manual workaround associated with a lot of code complexity. Refer to the SortableHeader and SortableColumn in the bayonet compartment for a sample of costs. You will find it at com.google.gwt.sample.expenses.gwt.client.ExpenseDetails . You can use this until something specific appears in the next version.

check directory: http://google-web-toolkit.googlecode.com/svn/trunk/bikeshed

+3
Jul 16 '10 at 10:09
source share

Workaround for click events:

 Header<String> columnHeader = new Header<String>(new ClickableTextCell()) { @Override public String getValue() { return columnName; } }; columnHeader.setUpdater(new ValueUpdater<String>() { @Override public void update(String value) { Window.alert("Header clicked!"); } }); table.addColumn(column, columnHeader); 
+8
Apr 15 2018-11-11T00:
source share

With the final version of GWT 2.1, is there support for sortable columns added to CellTable? Or does it still minimize your own decision after looking at the bikeshed example?

0
Nov 03 '10 at 19:33
source share
  CellTable<Contact> table = new CellTable<Contact>(); // Create name column. final TextColumn<Contact> nameColumn = new TextColumn<Contact>() { @Override public String getValue(Contact contact) { return contact.name; } }; // Create a data provider. ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>(); // Connect the table to the data provider. dataProvider.addDataDisplay(table); final List<Contact> list = dataProvider.getList(); for (Contact contact : CONTACTS) { list.add(contact); } final ListHandler<Contact> columnSortHandler = new ListHandler<Contact>( list); Header<String> columnHeader = new Header<String>(new ClickableTextCell()) { @Override public String getValue() { return "Name"; } }; columnHeader.setUpdater(new ValueUpdater<String>() { @Override public void update(String value) { if (Window.confirm("Want to do?")){ nameColumn.setSortable(true); columnSortHandler.setComparator(nameColumn, new Comparator<Contact>() { public int compare(Contact o1, Contact o2) { if (o1 == o2) { return 0; } // Compare the name columns. if (o1 != null) { return (o2 != null) ? o1.name.compareTo(o2.name) : 1; } return -1; } }); } else nameColumn.setSortable(false); } }); // Make the name column sortable. nameColumn.setSortable(false); // Create address column. TextColumn<Contact> addressColumn = new TextColumn<Contact>() { @Override public String getValue(Contact contact) { return contact.address; } }; // Add the columns. table.addColumn(nameColumn, columnHeader); table.addColumn(addressColumn, "Address"); // Add the data to the data provider, which automatically pushes it to the // widget. // Add a ColumnSortEvent.ListHandler to connect sorting to the // java.util.List. //------------------ Code to add --------------------------------// VerticalPanel vp = new VerticalPanel(); table.addColumnSortHandler(columnSortHandler); //------------------ Code end --------------------------------// // We know that the data is sorted alphabetically by default. table.getColumnSortList().push(nameColumn); // Add it to the root panel. vp.add(table); RootPanel.get().add(vp); 
0
Feb 23 2018-12-12T00:
source share



All Articles