0

Generally, for GWT list views of POJOs/DTOs I typically use a ListDataProider and a CellTable and place the CellTable into a Vertical Panel with a SimplePager. All is well.

I have a scenario where the Pojo's DTO is only 3 fields; and as such it would be nice to create a list view where I can put two columns of my DTO's next to each other and page accordingly. For example, instead of just three columns per row, there would be six where the first three columns represent one DTO instance and the next three (repeated) columns represent a second DTO instance.

Has anybody successfully done this before using celltables or other GWT component? Looking for a simple approach.

My fallback position (which is good enough) was to use a FlexTable with a search form and caping the results to 40 records. Two columns of 20 DTO's.

TylerH
  • 20,799
  • 66
  • 75
  • 101
slaman
  • 91
  • 1
  • 5

1 Answers1

0

I have done something similar. I was using a Grid. The key to align the components was this line of code:

myGrid.setWidget(position/COLUMNS_NUMBER+1, position%COLUMNS_NUMBER, lName);

Where lName was a GWT Label with the element (property) to be displayed (the 'name' property of my POJO / DTO). COLUMNS_NUMBER is my constant for how many columns I want to display.

I was displaying just this property, but you could easily adapt this idea to show more than one property of more than one DTO in different columns. My algorithm was just iterating through the DTO collection, getting each DTO's name prpoerty, which would be inserted as a Label in the Grid via setWidget, and updating the index variable position, which starts in 0.

I also needed this condition:

if(position%COLUMNS_NUMBER==0){
    list.insertRow(position/COLUMNS_NUMBER +1);
}

I'm displaying only onew property of each DTO, but the idea is also not having each one in a different row, and customizing the number of columns displayed. Again, you can adapt that to meet your needs, by adapting the way you increment the index variable position and the column where you display the DTO property or (even simpler) by following the same approach and just choosing a different property to display each time depending on

postiont%3 

since you want to show 3 properties of each DTO.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Diego
  • 462
  • 10
  • 26
  • Thanks. An interesting/clean approach. I'm going vertical with ordered data, so if displaying 20 rows...the 2nd column has the 21st record; and thus paging/scrolling becomes more complicated. – slaman Sep 03 '14 at 22:16
  • Sorry, I didn't get that from your question. I guess then it would be trickier. You need to hold your elements in a structure were you can get them by position, like a list, and do get(index) and get(index+20) (mod whatever, and you page/scroll?). You need to make sure that the element of the second column actually exists (that you can access that position in your collection). Where are you having problems? And please, don't forget to vote if you think it was a good answer. – Diego Sep 04 '14 at 02:34