Question

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!

Was it helpful?

Solution

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

OTHER TIPS

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;
  }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top