如何在codeigniter控制器中对JQgrid中的数据进行排序?

时间:2015-10-16 08:22:35

标签: php codeigniter sorting jqgrid

以下是我的控制器功能。当我点击列对数据进行排序时,它会向模型发送请求以获取已排序的数据,但我在for循环中修改数据以为某些列添加一些自定义数据。所以我编写了usort函数来对来自for循环的数据进行排序,但它只在当前页面上对数据进行排序。我是JQGrid的新手。请帮忙。

  public function getReports() {
        $arrResponceData = new stdClass();
        $strOrderByField = $this->input->get('sidx'); //get oderby field from grid
        $strOrderBySort = $this->input->get('sord'); //get sirting order
        $arrFilters = $this->input->get('filters');
        $intZerothPosition = 0;
        if (isset($arrFilters)) {
            $intSeletctedYear = $arrFilters[$intZerothPosition]['rules'][$intZerothPosition]['data'];
        }
        $arrSet['intSeletctedYear'] = $intSeletctedYear;
        $arrSet['strOrderBySort'] = $strOrderBySort;
        $arrSet['strOrderByField'] = $strOrderByField;
        //  print_r($arrSet);
        $this->session->set_userdata('accmeParsReport', $arrSet);
        if ($strOrderByField == "template" || $strOrderByField == "country" || $strOrderByField == "caseDiscussion") {
            $strOrderByField = "activity_name"; //userId is getting from query paramater
        }
        $arrAllActivityCount = $this->User_model->getAllActivityDetails($intLimit = "", $intStart = "", $strOrderBySort, $strOrderByField, $intSeletctedYear); //get total user count

        $intPage = $this->input->get('page'); //get to page count from grid
        $intLimit = $this->input->get('rows'); //get to show total records at a time in grid
        $intPageCount = 0;
        if (count($arrAllActivityCount) > 0) {
            if ($intLimit != 0) {
                $intPageCount = ceil(count($arrAllActivityCount) / $intLimit);
            } else {
                $intPageCount = count($arrAllActivityCount);
            }
        }
        if ($intPage > $intPageCount)
            $intPage = $intPageCount;
        if ($intPage < 1)
            $intPage = 1;
        $intStart = ($intLimit * $intPage) - $intLimit;
        $arrActivityDetails = $this->User_model
                ->getAllActivityDetails($intLimit, $intStart, $strOrderBySort, $strOrderByField, $intSeletctedYear);
        $arrResponceData->page = $intPage;
        $arrResponceData->total = $intPageCount;
        $arrResponceData->records = count($arrAllActivityCount);
        $strTemplate = 'Template D';
        for ($intIndex = 0; $intIndex < count($arrActivityDetails); $intIndex++) {
            $strStrToTime = strtotime($intSeletctedYear);
            $dateMyFormatForView = $intSeletctedYear;//date("Y", $strStrToTime);
            $intAMAPraCredits = $arrActivityDetails[$intIndex]['credit_hours'];
            if ($arrActivityDetails[$intIndex]['isBundled'] == "yes") {
                $strYear = date('Y', strtotime($arrActivityDetails[$intIndex]['expiration']));
                $arrActivityDetails[$intIndex]['expiration'] = $strYear . "-12-31 00:00:00";
                $arrActivityDetails[$intIndex]['credit_hours'] = $arrActivityDetails[$intIndex]['intCrditHours'];
                $intAMAPraCredits = isset($arrActivityDetails[$intIndex]['activityCompletedUsers']) ? $arrActivityDetails[$intIndex]['activityCompletedUsers'] : "0.00";
                $arrActivityDetails[$intIndex]['certificate_title'] = $arrActivityDetails[$intIndex]['certificate_title_name'];
            }
            $arrResponceData->rows[$intIndex]['cell'] = array(
                $arrActivityDetails[$intIndex]['activity_id'],
                $strTemplate, $arrActivityDetails[$intIndex]['accme_id'],
                $arrActivityDetails[$intIndex]['prov_id'], $dateMyFormatForView,
                $arrActivityDetails[$intIndex]['certificate_title'], $arrActivityDetails[$intIndex]['expiration'],
                $arrActivityDetails[$intIndex]['city'], $arrActivityDetails[$intIndex]['state'],
                'USA', $arrActivityDetails[$intIndex]['providership'],
                $arrActivityDetails[$intIndex]['pars_type'], $arrActivityDetails[$intIndex]['credit_hours'],
                $arrActivityDetails[$intIndex]['do'], $arrActivityDetails[$intIndex]['notDo'],
                $arrActivityDetails[$intIndex]['comm_support'], $arrActivityDetails[$intIndex]['competence'],
                $arrActivityDetails[$intIndex]['comp_eval'], $arrActivityDetails[$intIndex]['performance'],
                $arrActivityDetails[$intIndex]['perf_eval'], $arrActivityDetails[$intIndex]['outcomes'],
                $arrActivityDetails[$intIndex]['out_eval'], 'No',
                'No', 'No', 'No', 'No', 'No', 'No',
                $arrActivityDetails[$intIndex]['providers'], $intAMAPraCredits,
                '', $arrActivityDetails[$intIndex]['patient_care'],
                );
        }

        if ($strOrderByField == 'certificate_title') {

            if ($strOrderBySort == 'asc') {

                $sort = $arrResponceData->rows;

                usort($sort, array($this, 'method3'));

                $arrResponceData->rows = $sort;
            } else {
                $sort = $arrResponceData->rows;
                usort($sort, array($this, 'method4'));
                $arrResponceData->rows = $sort;
            }
        }

        echo json_encode($arrResponceData);
    }

0 个答案:

没有答案