jqGrid with JSON data renders table as empty

后端 未结 9 2288
孤独总比滥情好
孤独总比滥情好 2020-12-30 06:39

I\'m trying to create a jqgrid, but the table is empty. The table renders, but the data doesn\'t show.

The data I\'m getting back from the php call is:



        
9条回答
  •  悲&欢浪女
    2020-12-30 07:34

    This might be a older post but I will post my success just to help others.

    Your JSON needs to be in this format:

    {
    "rows": [
        {
            "id": 1,
            "cell": [
                1,
               "lname",
                "fname",
                "mi",
                phone,
                "cell1",
                "cell2",
                "address",
                "email"
            ]
        },
        {
            "id": 2,
            "cell": [
                2,
                "lname",
                "fname",
                "mi",
                phone,
                "cell1",
                "cell2",
                "address",
                "email"
            ]
        }
    ]
    

    }

    and I wrote this model in Zend so you can use it if you feel like it. Manipulate it how you want.

    public function fetchall ($sid, $sord)
    {
        $select = $this->getDbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
        $select->setIntegrityCheck(false)
               ->join('Subdiv', 'Subdiv.SID = Contacts.SID', array("RepLastName" => "LastName", 
                                                                    "Subdivision" => "Subdivision",
                                                                    "RepFirstName" => "FirstName"))
               ->order($sid . " ". $sord);
    
        $resultset = $this->getDbTable()->fetchAll($select);
        $i=0;
        foreach ($resultset as $row) {
            $entry  = new Application_Model_Contacts();
    
            $entry->setId($row->id);
            $entry->setLastName($row->LastName);
            $entry->setFirstName1($row->FirstName1);
            $entry->setFirstName2($row->FirstName2);
            $entry->setHomePhone($row->HomePhone);
            $entry->setCell1($row->Cell1);
            $entry->setCell2($row->Cell2);
            $entry->setAddress($row->Address);
            $entry->setSubdivision($row->Subdivision);
            $entry->setRepName($row->RepFirstName . " " . $row->RepLastName);
            $entry->setEmail1($row->Email1); 
            $entry->setEmail2($row->Email2);
    
            $response['rows'][$i]['id'] = $entry->getId(); //id
            $response['rows'][$i]['cell'] = array (
                                                    $entry->getId(),
                                                    $entry->getLastName(),
                                                    $entry->getFirstName1(),
                                                    $entry->getFirstName2(),
                                                    $entry->getHomePhone(),
                                                    $entry->getCell1(),
                                                    $entry->getCell2(),
                                                    $entry->getAddress(),
                                                    $entry->getSubdivision(),
                                                    $entry->getRepName(),
                                                    $entry->getEmail1(),
                                                    $entry->getEmail2()
                                                );
            $i++;
    
        }
        return $response;
    }
    

提交回复
热议问题