You can represent your "rows" as List<String>
instances, you have to change your parameterization from String to List in your Grid, Column and data provider; and of course you have to call updateRowData with a List<List<String>>
, not a List<String>
.
You also need one Column instance per column, taking the value out of the List by index:
class IndexedColumn extends Column<List<String>, String> {
private final int index;
public IndexedColumn(int index) {
super(new EditTextCell());
this.index = index;
}
@Override
public String getValue(List<String> object) {
return object.get(this.index);
}
}
How do i add sorting to this example. I tried a ListHandler
but not sure how to compare List<String>
. Any help is appreciated.
You need to add a
ListHandler
to each column you want to sort separately. Kind of like this:You'll have to add a getter method to
IndexedColumn
for theindex
:Then you'll need to add a
ListHandler
to theCellTable
:In the example above
list
is theList<List<String>>
object. ThecolumnName
is theColumn
object. You'll have to do this for every column you want to sort.Don't forget to also call
.setSortable(true)
on each of the columns that you will sort.A good basic example of column sorting can be found here. The code above is based on this example but I used your
index
inIndexedColumn
in order to get the properString
for the column to do the comparison.Here is the data grid code
Here is the actual class