Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-8212

Pagination using sort criteria produces inconsistent page results

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.4.0, 3.4.1, 4.0.0, 4.0.1
    • Fix Version/s: Unscheduled
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      Not sure why the db would be doing this, but here's what happens:
      We have a profile listing of churches: http://www.ecww.org/civicrm/profile?force=1&gid=9&reset=1
      If you sort by City ASC, you'll get 3 churches in Vancouver at the bottom of page 2, and one church in Vancouver at the top of page 3.
      Paging between 2 and 3 produces a different set of Vancouver churches on each page refresh.

      My fix is to explicitly sort on all additional columns in sequence after the primary sort column. I suppose there could be a performance hit if the primary column or subsequent columns are too homogeneous and there's lots of data. Maybe there's a better way to do it with a single row number column or an id instead.

      Change to CRM_Utils_Sort

      function orderBy( ) {
      if ( ! CRM_Utils_Array::value( $this->_currentSortID, $this->_vars ) )

      { return ''; }

      $orderBy = array();
      $direction = ' asc';

      if ( $this->_vars[$this->_currentSortID]['direction'] == self::ASCENDING ||
      $this->_vars[$this->_currentSortID]['direction'] == self::DONTCARE )

      { $direction = ' asc'; }

      else

      { $direction = ' desc'; }

      //primary sort column
      $this->vars[$this->_currentSortID]['name'] = str_replace( ' ', '', $this->_vars[$this->_currentSortID]['name'] );
      $orderBy []= $this->_vars[$this->_currentSortID]['name'];

      //secondary sort columns; required for consistent results
      foreach($this->_vars as $id => $sorter) {
      if ( $this->_currentSortID != $id )

      { $sorter['name'] = str_replace( ' ', '_', $sorter['name'] ); $orderBy []= $sorter['name']; }


      }

      return implode(', ',$orderBy) . $direction;
      }

        Attachments

          Activity

            People

            • Assignee:
              lobo Donald A. Lobo
              Reporter:
              toddwallar Todd Wallar
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: