我如何更正jqgrid页脚信息?

时间:2011-01-10 11:22:53

标签: cakephp jqgrid

我在我的一个应用程序中使用jqgrid。 现在我面临一个奇怪的问题,不知道如何纠正它?

实际上在其中一个报告中(有多个链接),即使表中有记录,jqgrid也会显示错误的页脚信息,即显示Page 0 of 0。

这是运行的代码:

if( isset($this->params['named']['ajax']) && $this->params['named']['ajax'] == '1' )
    {

        $this->autoRender = false;

        // get how many rows we want to have into the grid - rowNum parameter in the grid
        $limit = $this->params['url']['rows'];

        // get index row - i.e. user click to sort. At first time sortname parameter -
        // after that the index from colModel
        $sidx = $this->params['url']['sidx'];

        // sorting order - at first time sortorder
        $sord = $this->params['url']['sord'];

        $page = $this->params['url']['page'];

        // if we not pass at first time index use the first column for the index or what you want
        if( !$sidx ) $sidx = 1;

        // calculate the number of rows for the query. We need this for paging the result
         $findconditions = array();
        if(!empty($this->params['named']['batch']))
            array_push(&$findconditions, array('Batch.id' => $this->params['named']['batch'] ));
          $row = $this->Placement->find('count',array(
                    'link' => array(
                    'Student' => array(
                        'Batch'
                    )
                    ),
                    'conditions'=> $findconditions
          ));
        $count = $row;

        // calculate the total pages for the query
        if( $count > 0 )
        {
            $total_pages = ceil($count / $limit);
        }
        else
        {
            $total_pages = 0;
        }

        // if for some reasons the requested page is greater than the total
        // set the requested page to total page
        if( $page > $total_pages ) $page = $total_pages;

        // calculate the starting position of the rows
        $start = $limit * $page - $limit;

        // if for some reasons start position is negative set it to 0
        // typical case is that the user type 0 for the requested page
        if( $start < 0 ) $start = 0;

        // the actual query for the grid data
        $limit_range = $start . "," . $limit;
        $sort_range = $this->modelClass . '.' . $sidx . " " . $sord;

        $this->Placement->recursive = -1;
         $where='';
        if( $this->params['url']['_search'] == 'true' )
        {
            //pr($this->params);

            $searchconditions = array();

            if( isset($this->params['named']['batch']) && !empty($this->params['named']['batch']) )
            {
              $where.= " Batch.id =".$this->params['named']['batch'];
            }
            if( isset($this->params['url']['isstillworking']) && !empty($this->params['url']['isstillworking']) )
            {
              $where.= " AND Placement.isstillworking ='".$this->params['url']['isstillworking']."'";
            }
            if( isset($this->params['url']['studentname']) && !empty($this->params['url']['studentname']) )
            {
              $where.=" AND Student.fullname LIKE '" .$this->params['url']['studentname'] . "%'";
            }
             if( isset($this->params['url']['companyname']) && !empty($this->params['url']['companyname']) )
            {
                $where.=" AND Company.name LIKE '" .$this->params['url']['companyname'] . "%'";

            }
            if( isset($this->params['url']['salary']) && !empty($this->params['url']['salary']) )
            {
              $where.= " AND Placement.salary =".$this->params['url']['salary'];

            }
            if( isset($this->params['url']['contactnumber1']) && !empty($this->params['url']['contactnumber1']) )
            {
                 $where.= " AND Student.contactnumber1 =".$this->params['url']['contactnumber1'];
            }
             if( isset($this->params['url']['batchname']) && !empty($this->params['url']['batchname']) )
            {
                $where.=" AND Batch.name LIKE '" .$this->params['url']['batchname'] . "%'";
            }



            $sql="SELECT Student.fullname, 
                Placement.isstillworking, 
                Company.id,
                Company.name,
                Placement.id,
                Placement.salary,
                Placement.created, 
                Student.id, 
                Student.contactnumber1, 
                Batch.id,
                Batch.name
            FROM placements Placement
            INNER JOIN (

                    SELECT student_id, isstillworking, max( created ) AS other_col
                        FROM placements
                        GROUP BY student_id
                        ) AS b ON Placement.student_id = b.student_id
                        AND Placement.created = b.other_col
            INNER JOIN students Student ON ( Student.id = Placement.student_id )
            INNER JOIN batches Batch ON ( Student.batch_id = Batch.id )
            INNER JOIN companies Company ON ( Company.id = Placement.company_id )
            WHERE ".$where. 
            "  AND Student.type='student' 
               AND Student.trainingcompleted=1
             ORDER BY ".$sort_range."
             LIMIT ".$limit_range
             ;
            $result=$this->Placement->query($sql);


        }
        else
        {
                $sql="SELECT Student.fullname, 
                Placement.isstillworking, 
                Company.id,
                Company.name,
                Placement.id,
                Placement.salary,
                Placement.created, 
                Student.id, 
                Student.contactnumber1, 
                Batch.id,
                Batch.name
            FROM placements Placement
            INNER JOIN (

                    SELECT student_id, isstillworking, max( created ) AS other_col
                        FROM placements
                        GROUP BY student_id
                        ) AS b ON Placement.student_id = b.student_id
                        AND Placement.created = b.other_col
            INNER JOIN students Student ON ( Student.id = Placement.student_id )
            INNER JOIN batches Batch ON ( Student.batch_id = Batch.id )
            INNER JOIN companies Company ON ( Company.id = Placement.company_id )
            WHERE Batch.id =
            ".$this->params['named']['batch'].
            " AND Student.type='student' 
              AND Student.trainingcompleted=1
             ORDER BY ".$sort_range."
             LIMIT ".$limit_range
             ;
            $result=$this->Placement->query($sql);
        }

        $i = 0;
        $response->page = $page;
        $response->total = $total_pages;
        $response->records = $count;

        //pr($result);

        foreach($result as $result)
        {
            $response->rows[$i]['id'] = $result['Placement']['id'];

            $student = "<a href='" . APP_URL . "placements/report18/studentid:" . $result['Student']['id']."'>" . $result['Student']['fullname'] . "</a>";
            $company = "<a href='" . APP_URL . "companies/view/" . $result['Company']['id'] . "'>" . $result['Company']['name'] . "</a>";
            $batch = "<a href='" . APP_URL . "batches/view/" . $result['Batch']['id'] . "'>" . $result['Batch']['name'] . "</a>";
            $contactnumber1 =$result['Student']['contactnumber1'];
            $response->rows[$i]['cell'] = array($student, $result['Placement']['isstillworking'], $result['Company']['name'], $result['Placement']['salary'], $contactnumber1, $batch);
            $i++;
        }

        echo json_encode($response);

    }

我也附上了屏幕截图供参考。 alt text

请帮我解决这个问题。

此致

的Pankaj

1 个答案:

答案 0 :(得分:0)

为什么你不会使用Cake的ORM层和Pagination类?如果你使用Model->query(),你必须自己逃避输入!