Multiple Pagination in single page

  • Controller =>
    

    public function getPagination($query, $pageSize) {

        $queryDataCount = new Pagination(['totalCount' => $query->count()]);
    
        $queryDataCount->setPageSize($pageSize);
    
        $paginatedData = $query->offset($queryDataCount->offset)
        ->limit($queryDataCount->limit)
        ->all();   
    
        return array($paginatedData, $queryDataCount);
    }
    
    $queryMonthly   = QuizLeaderboard::find()
    ->select(['SUM(score) as totalScore', 'SUM(time) as totalTime', 'userId'])
    ->where(['between', 'currentDate', $monthStart, $monthEnd])
    ->asArray();
    
    $paginatedQueryMonthly = $this->getPagination($queryMonthly, 10);       
    //$paginatedQueryMonthly[1]->pageParam = 'list1Page';
    
    $queryWeekly   = QuizLeaderboard::find()
    ->select(['SUM(score) as totalScore', 'SUM(time) as totalTime', 'userId'])
    ->where(['between', 'currentDate', $monthStartSec, $monthEndSec])
    ->asArray();
    
     $paginatedQueryWeekly =$this->getPagination($queryWeekly, 10);
     $paginatedQueryWeekly[1]->pageParam = 'list2Page';
    
     $queryTwoWeeks   = QuizLeaderboard::find()
     ->select(['SUM(score) as totalScore', 'SUM(time) as totalTime', 'userId'])
     ->where(['between', 'currentDate', $monthStartTh, $monthEndTh])
     ->asArray();
    
     $paginatedQueryTwoWeeks =$this->getPagination($queryTwoWeeks, 10);
     $paginatedQueryTwoWeeks[1]->pageParam = 'list3Page';
    

    This is how i am sending data to view=>

     return $this->render('summarize-report', [
    
                'queryMonthly' => $paginatedQueryMonthly[0],
                'pagesQueryMonthly' => $paginatedQueryMonthly[1],
    
                'queryWeekly' => $paginatedQueryWeekly[0],
                'pagesQueryWeekly' => $paginatedQueryWeekly[1],
    
                'queryTwoWeeks' => $paginatedQueryTwoWeeks[0],
                'pagesQueryTwoWeeks' => $paginatedQueryTwoWeeks[1],
                'reports' => $query,
       ]);
    
  • View=>
    

    echo LinkPager::widget([‘pagination’ => $pagesQueryWeekly,]);

    echo LinkPager::widget([‘pagination’ => $pagesQueryTwoWeeks,]);

    echo LinkPager::widget([ ‘pagination’ => $pagesQueryMonthly,]);

    Pagination is not changing pages. can anyone help me find out the problem?

Hi @pusku, welcome to the forum.

You are setting pageParam of the Pagination objects after you’ve got them and the corresponding pagenated data in getPagination() method. I think you should pass the pageParam to the method and set it to the Pagenation object before you refer to Pagenation::offset.