Reputation: 45
I am trying to add row number column to Cell Table where in the row number should be associated with each object. Meaning, if any column is sorted the serial number should not be changed for that particular row. Example: Before Sorting SrNo order is 1 2 3 4 ... After Sorting on some column SrNo order is 4 9 5 7
Any help will be greatly appreciated.
Thanks!
Upvotes: 1
Views: 1118
Reputation: 64
If I understand you correctly you want a column at the side that reads 1 2 3 4 5 no matter if the table is sorted or not, it will simply count the rows.
dataCollection is the AsyncDataProvider
Also possible duplicate of this: Adding a row-number column to GWT CellTable
Code:
TextColumn<Row> numColumn = new TextColumn<Row>() {
@Override
public String getValue(Row object) {
return Integer.toString(dataCollection.indexOf(object))+1;
}
};
Upvotes: 1
Reputation: 453
The most common (and easy) solution is to do it exactly as you say - if the row number should be associated with each object, then just associate that number with specific object. Add the
int rowNumber
to class of data that should be displayed in CellTable and then just display rowNumber in some column of celltable. If you cannot change that class, inherit from it and add rowNumber variable.
If there are some problems with this solution or you have some restrictions, please update your question with more info (because there isn't much of it) and I can update my answer
Upvotes: 2