Wicket
  1. Wicket
  2. WICKET-3678

GridView to fill columns first (top-down, then left-right)

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.4.17
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:
      None

      Description

      GridView fills the table by rows. Filling by columns is needed too.

      Since it uses DataProvider's iterator and by nature of HTML tables, the data need to come in the order of row's cells,
      the best approach I've found is to reorder the list appropriately.

         private void recalculateList2() {
            int cols = this.getColumns();
            // Column height.
            int colHeight = list.size() / cols;
            // Last items may not fit whole row.
            colHeight += ( (list.size() % cols) == 0 ? 0 : 1 );
            
            list2 = new ArrayList<T>( list );
            for ( int i = 0; i < list.size(); i++ ) {
               int newIndex = (i % colHeight) * cols + (i / colHeight);
               list2.set( newIndex, list.get(i) );
            }
         }
      

      Computing the right position in a custom Iterator might be even better - no need for an extra ArrayList.

        Issue Links

          Activity

          Show
          Ondra Žižka added a comment - http://ondrazizka.googlecode.com/svn/trunk/bots/JawaBot/branches/2.0/web/src/main/java/cz/dynawest/wicket/ListColumnGridDataProvider.java
          Hide
          Ondra Žižka added a comment -

          Btw this is ugly solution in that the columns must be set twice:

                add( new GridView<String>( "chess", new ListColumnGridDataProvider(SITES).setColumns(3) ) {
                   ...
                }.setColumns(3) );
          

          Wicket experts will surely come up with something better

          Show
          Ondra Žižka added a comment - Btw this is ugly solution in that the columns must be set twice: add( new GridView< String >( "chess" , new ListColumnGridDataProvider(SITES).setColumns(3) ) { ... }.setColumns(3) ); Wicket experts will surely come up with something better

            People

            • Assignee:
              Unassigned
              Reporter:
              Ondra Žižka
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development