4 Replies Latest reply on Oct 16, 2009 4:20 AM by gizola

    DataTable RowKeyVar problem

    gizola

      Hi!

      I'm facing a small problem. Due to performance reasons I've created an own datamodel for the rich:datatable component. In this datamodel (wich extends ModifiableModel) I check wether the sorting or filtering has been changed since last rendering, or not. If not I use the cached data to display the records (wich incredibly increases paging perfomance with datascroller for huge datasets!) and if only the sorting changed, I resort the cached data without retrieving the whole dataset, refiltering and then sorting as implemented in ExtendedDataModel.

      Now the problem is that if I define a rowkeyvar in the DataTable to display row numbers, the row numbers are mixed upon filtering or sorting.

      Like:

      Datatable using normal data model:

      rowkeyvar data
      1. something
      2. anything
      


      Now this sorted by data:
      rowkeyvar data
      1. anything
      2. something
      


      With my datamodel:
      rowkeyvar data
      1. something
      2. anything
      


      Now this sorted by data:
      rowkeyvar data
      2. anything
      1. something
      


      As you see the rowkeyvar was maintained and "mixed". This also happens with filtering.

      I know the reason: the original data list from the dataprovider is untouched and the rowkeys are maintained for the original list.

      My question is how to implement a "rownum" variable similar to rowkeyvar where I could display always the correct row number from 1 to rowcount?

      I examined the UIDataAdaptor code a lot to implement a RowNum variable similar to RowKeyVar, but no idea till now how to reset it and increment it by row to row.

      Thank you in advance!

      Regards,

      Gizola

      PS: oh, yes, Richfaces 3.3.0 GA I'm using.

        • 1. Re: DataTable RowKeyVar problem
          nbelaevski

          Hi Gizola,

          Model generates row keys in walk(...) method. You can override it to generate sequential keys for rows.

          • 2. Re: DataTable RowKeyVar problem
            gizola

            Hi!

            Thanks for the answer. Now this is my walk method:

            @Override
             public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) throws IOException
             {
             final SequenceRange seqRange = (SequenceRange) range;
             int rows = seqRange.getRows();
             int rowCount = getRowCount();
             int currentRow = seqRange.getFirstRow();
             if (rows > 0)
             {
             rows += currentRow;
             rows = Math.min(rows, rowCount);
             }
             else
             {
             rows = rowCount;
             }
             for (; currentRow < rows; currentRow++)
             {
             visitor.process(context, rowKeys.get(currentRow), argument);
             }
             }
            


            The currentRow variable contains the sequential key, but I have to get the apropriate rowKey from the rowKeys to display correct row in the datatable. How to implement here a sequential row key when the rowKeys are mixed in my rowKeys variable (according to sorting and filtering)?

            Thank you for helping.

            Regards,

            Gizola

            • 3. Re: DataTable RowKeyVar problem
              gizola


              Well I finally solved the problem. I had to override getRowKey and setRowKey methods also (or at least make small changes in them).

              Not it is working.

              Thanks for the hint.

              Regards,

              Gizola

              • 4. Re: DataTable RowKeyVar problem
                gizola

                "Not it is working" was of course mistyped :)

                Now it is working is the right sentense.

                Regards,

                Gizola