3 Replies Latest reply on Apr 30, 2009 10:09 PM by tw

    Sorting and selection in scrollableDataTable

    tw

      Table and server-side state get out of sync when sorting the table. I see the data model is recreated after clicking the sortable header. The table is then rendered from this on-the-fly created model, with proper sorting. But when I select any of the rows, the row index will now refer to the actual source list of the table, which is not sorted. How an I make sure that the backing list is sorted instead of an internally created model to ensure that selection works?


      ModifiableModel$RowKeyWrapperFactory(ObjectWrapperFactory).convertList(List, ObjectConvertor) line: 138
      ModifiableModel$RowKeyWrapperFactory(ObjectWrapperFactory).wrapList(List) line: 175
      ModifiableModel.sort(List<SortField2>) line: 265
      ModifiableModel.modify(List, List<SortField2>) line: 234
      HtmlScrollableDataTable(UIScrollableDataTable).createDataModel() line: 223
      HtmlScrollableDataTable(UIDataAdaptor).getExtendedDataModel() line: 621
      HtmlScrollableDataTable(UIDataAdaptor).getRowCount() line: 248

      <rich:scrollableDataTable id="scrollableTestTable"
       value="#{EdtTestBean.rowIds}" var="rowId" selectionMode="multi"
       tableState="#{EdtTestBean.tableState}"
       selection="#{EdtTestBean.selection}" selectedClass="selected"
       rowClasses="tablerow1,tablerow2" columnsWidth="0*" width="100%"
       height="308px">
      
       <rich:columns id="#{col.name}" value="#{tableColumns}" var="col"
       index="colIndex" label="#{col.description}" sortable="true"
       sortExpression="#{EdtTestBean.getRow(rowId)[colIndex].value}"
       sortIconAscending="dataTableAscIcon"
       sortIconDescending="dataTableDescIcon">
       <f:facet name="header">
       <h:outputText value="#{col.description}" />
       </f:facet>
       <h:outputText value="#{EdtTestBean.getRow(rowId)[colIndex].value}" />
       </rich:columns>
      </rich:scrollableDataTable>
      


        • 1. Re: Sorting and selection in scrollableDataTable
          ilya_shaikovsky
          • 2. Re: Sorting and selection in scrollableDataTable
            konstantin.mishin

            We don't sort your backing list. If you wish to sort it you should use your custom model as value.

            • 3. Re: Sorting and selection in scrollableDataTable
              tw

              In case anybody is looking for this, here is an example (would be helpful to have this somewhere in the documentation or KB):

               // sortExpression="#{someComponent.getSortValues(rowId)[colIndex]}"
              
               private ScrollableTableDataModel<Long> tableDataModel = new ScrollableTableDataModel<Long>() {
              
               @Override
               public List<Long> loadData(int startRow, int endRow, SortOrder sortOrder) {
               // this method is called twice in the case of sorting: first during decode and then during encode, with sort order
               if (sortOrder != null) {
               ScrollableTableDataModel sortableModel = new org.richfaces.model.internal.ComponentSortableDataModel("rowId", rowIds, sortOrder);
               return sortableModel.loadData(startRow, endRow, sortOrder);
               }
               return rowIds;
               }
              
               @Override
               public int getRowCount() {
               if (rowIds != null) {
               return rowIds.size();
               }
               return 0;
               }
              
               @Override
               public Object getWrappedData() {
               throw new UnsupportedOperationException();
               }
              
               @Override
               public void setWrappedData(Object data) {
               throw new UnsupportedOperationException();
               }
              
               @Override
               public Object getId(Long o) {
               return o.intValue();
               }
              
              };