1

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!

Tia It
  • 45
  • 5

2 Answers2

2

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

Miroslav
  • 444
  • 1
  • 7
  • 21
1

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;
  }
};
Community
  • 1
  • 1
Sheogora
  • 64
  • 2
  • 12
  • Solution looks good. The problem with above approach is that if my dataCollection has thousands of records, indexOf(object) will iterate through the complete list for each row/record which is undoubtedly hitting performance. – Tia It Jul 09 '13 at 20:55