문제

JQGRID를 만들려고하지만 테이블은 비어 있습니다. 테이블은 렌더링하지만 데이터는 표시되지 않습니다.

PHP 호출에서 돌아온 데이터는 다음과 같습니다.

{
"page":"1",
"total":1,
"records":"10",
"rows":[
{"id":"2:1","cell":["1","image","Chief Scout","Highest Award test","0"]},
{"id":"2:2","cell":["2","image","Link Badge","When you are invested as a Scout, you may be eligible to receive a Link Badge. (See page 45)","0"]},
{"id":"2:3","cell":["3","image","Pioneer Scout","Upon completion of requirements, the youth is invested as a Pioneer Scout","0"]},
{"id":"2:4","cell":["4","image","Voyageur Scout Award","Voyageur Scout Award is the right after Pioneer Scout.","0"]},
{"id":"2:5","cell":["5","image","Voyageur Citizenship","Learning about and caring for your community.","0"]},
{"id":"2:6","cell":["6","image","Fish and Wildlife","Demonstrate your knowledge and involvement in fish and wildlife management.","0"]},
{"id":"2:7","cell":["7","image","Photography","To recognize photography knowledge and skills","0"]},
{"id":"2:8","cell":["8","image","Recycling","Demonstrate your knowledge and involvement in Recycling","0"]},
{"id":"2:10","cell":["10","image","Voyageur Leadership ","Show leadership ability","0"]},
{"id":"2:11","cell":["11","image","World Conservation","World Conservation Badge","0"]}
]}

JavaScript 구성은 다음과 같습니다.

$("#"+tableId).jqGrid ({
    url:'getAwards.php?id='+classId,
    dataType : 'json',
    mtype:'POST',
    colNames:['Id','Badge','Name','Description',''],
    colModel : [
        {name:'awardId', width:30, sortable:true, align:'center'},
        {name:'badge', width:40, sortable:false, align:'center'},
        {name:'name', width:180, sortable:true, align:'left'},
        {name:'description', width:380, sortable:true, align:'left'},
        {name:'selected', width:0, sortable:false, align:'center'}
        ],
    sortname: "awardId",
    sortorder: "asc",
    pager: $('#'+tableId+'_pager'),
    rowNum:15,
    rowList:[15,30,50],
    caption: 'Awards',
    viewrecords:true,
    imgpath: 'scripts/jqGrid/themes/green/images',
    jsonReader : { 
        root: "rows", 
        page: "page", 
        total: "total", 
        records: "records", 
        repeatitems: true, 
        cell: "cell", 
        id: "id",
        userdata: "userdata", 
        subgrid: {root:"rows", repeatitems: true, cell:"cell" } 
    },
    width: 700,
    height: 200
});

HTML은 다음과 같습니다.

<table class="awardsList" id="awardsList2" class="scroll" name="awardsList" />
<div id="awardsList2_pager" class="scroll"></div>

기본값을 유지하려고했기 때문에 JSONREADER를 정의해야할지 확신 할 수 없습니다. PHP 코드가 도움이되면 게시 할 수 있습니다.

도움이 되었습니까?

해결책

나는 그것을 일하기 위해 그것을 얻었다!

그만큼 데이터 형식 필드가되어야합니다 데이터 형식. 사례에 민감합니다.

다른 팁

스크립트를 포함시킬 때도 문제가 발생합니다 jquery.jqgrid.min.js 그 전에 Grid.locale-en.js. 컨트롤러 메소드 호출에 문제가있는 경우 확인하십시오.

JQGRID 3.6에서 JQGRID 3.7.2로 마이그레이션 할 때 동일한 문제가 발생했습니다. 문제는 JSON이 JSON 사양에 따라 제대로 인용되지 않았다는 것입니다. JQGRID 3.6 내 잘못된 JSON을 허용했지만 JQGRID 3.7은 더 엄격합니다.

여기에서 참조 : http://simonwillison.net/2006/oct/11/json/

유효하지 않은:

{
page:"1",
total:1,
records:"10",
rows:[
    {"id":"2:1","cell":["1","image","Chief Scout","Highest Award test","0"]},
    {"id":"2:2","cell":["2","image","Link Badge","When you are invested as a Scout, you may be eligible to receive a Link Badge. (See page 45)","0"]},
    {"id":"2:3","cell":["3","image","Pioneer Scout","Upon completion of requirements, the youth is invested as a Pioneer Scout","0"]}
]}

유효한:

{
"page":"1",
"total":1,
"records":"10",
"rows":[
    {"id":"2:1","cell":["1","image","Chief Scout","Highest Award test","0"]},
    {"id":"2:2","cell":["2","image","Link Badge","When you are invested as a Scout, you may be eligible to receive a Link Badge. (See page 45)","0"]},
    {"id":"2:3","cell":["3","image","Pioneer Scout","Upon completion of requirements, the youth is invested as a Pioneer Scout","0"]}
]}

나는 또한 그것을 작동시켰다 : 데이터 유형은 올바른 철자이다 - 그것은 예에서 그렇게 보여 지지만 그것은 일치하지 않는다. 모든 것 도서관에서 다른 것이 틀리기 쉬웠습니다.

나는이 희박한 문서를 쫓는 데 매우 피곤해졌고 JavaScript에서 사용하기에 적합한 JSON이 실제로 XML에 유리한 짧은 적용 범위를 받았다고 생각합니다. Python과 JavaScript는 JSON을 통해 함께 함께 강력한 조합이지만이 특정 라이브러리와의 끊임없는 투쟁입니다.

대안이있는 사람 :

1> jQuery UI 테마를 올바르게 지원합니다 (둥근 모서리 포함!) (http://datatables.net 테마에 대한 훨씬 더 잘 지원됩니다)

2> 열 크기 조정 허용 (http://datatables.net 상자에서 이것을 지원하지 않습니다)

3> 하위 그리드 허용 (http://datatables.net 이벤트를 통해 여기서 원하는대로 할 수 있습니다)

알려주세요. 나는 나머지 전체 전체보다 내 인터페이스의 한 부분에 더 많은 시간을 보내고 있으며, 그것은 단지 성가신 예제와 "시도하는 것"을 검색하는 데 소요되는 모든 시간입니다.

에스

이것은 오래된 게시물 일지 모르지만 다른 사람들을 돕기 위해 내 성공을 게시 할 것입니다.

JSON은이 형식이어야합니다.

{
"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"
        ]
    }
]

}

그리고 나는이 모델을 Zend에 썼으므로 기분이 좋으면 사용할 수 있습니다. 원하는 방식을 조작하십시오.

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;
}

사람들은 단지 이것에 당신을 도와주고 싶어합니다. 나는 다음과 같은 일을했다 :

JSON

var mydata1 = { "page": "1", "total": 1, "records": "4","rows": [{ "id": 1, "cell": ["1", "cell11", "values1" ] },
    { "id": 2, "cell": ["2", "cell21", "values1"] },
    { "id": 3, "cell": ["3", "cell21", "values1"] },
    { "id": 4, "cell": ["4", "cell21", "values1"] }
]};

// 중요한 선 아래에 표시됩니다. Datatype "JSonstring"은 "JSON"대신 저를 위해 일했습니다.

datatype: "jsonstring",

contentType: "application/json; charset=utf-8",

datastr: mydata1,

colNames: ['Id1', 'Name1', 'Values1'],

colModel: [
      { name: 'id1', index: 'id1', width: 55 },
      { name: 'name1', index: 'name1', width: 80, align: 'right', sorttype: 'string' },
      { name: 'values1', index: 'values1', width: 80, align: 'right', sorttype: 'string'}],

문안 인사,

필자의 경우 문제는 다음과 같은 PHP 코드 라인 (JQGRID 데모에서 가져온)으로 인해 발생했습니다.

$responce->page = $page;

여기서 잘못된 점은 다음과 같습니다. 객체의 속성 페이지에 액세스하고 있습니다. $responce 먼저 만들지 않고. 이로 인해 Apache가 다음 오류 메시지를 표시하게되었습니다.

Strict Standards: Creating default object from empty value in /home/mariusz/public_html/rezerwacja/apps/frontend/modules/service/actions/actions.class.php on line 35

마지막으로 오류 메시지는 스크립트 내에서 JSON 리더에게 전송되었습니다.

빈 개체를 만들어 문제를 해결했습니다.

$responce = new stdClass();

나는 당신의 신분증이 올바른 유형이라고 생각하지 않습니다. int라고 생각합니다.

주어진 JSON의 경우 JSONREADER 설정이 필요하지 않습니다. 당신이 나열한 것은 어쨌든 기본값이며, 당신은 당신의 JSON에 서브 그리드가 없습니다.

이 시도:

{
"page":"1",
"total":1,
"records":"10",
"rows":[
{"id":1 ,"cell":["1","image","Chief Scout","Highest Award test","0"]},
{"id":2,"cell":["2","image","Link Badge","When you are invested as a Scout, you maybe eligible to receive a Link Badge. (See page 45)","0"]},
{"id":3,"cell":["3","image","Pioneer Scout","Upon completion of requirements, the youth is invested as a Pioneer Scout","0"]},
{"id":4,"cell":["4","image","Voyageur Scout Award","Voyageur Scout Award is the right after Pioneer Scout.","0"]},
{"id":5,"cell":["5","image","Voyageur Citizenship","Learning about and caring for your community.","0"]},
{"id":6,"cell":["6","image","Fish and Wildlife","Demonstrate your knowledge and involvement in fish and wildlife management.","0"]},
{"id":7,"cell":["7","image","Photography","To recognize photography knowledge and skills","0"]},
{"id":8,"cell":["8","image","Recycling","Demonstrate your knowledge and involvement in Recycling","0"]},
{"id":9,"cell":["10","image","Voyageur Leadership ","Show leadership ability","0"]},
{"id":10,"cell":["11","image","World Conservation","World Conservation Badge","0"]}
]}

나는 WAMP 2.4와 함께 일하고 있었고,이 문제에 미쳤고, 이전 버전의 PHP를 설치하는 것과 같은 많은 것들을 시도했고, 5.2, Windows XP에서 시도한 Een 및 많은 JQGRID 옵션을 시도했습니다. 마침내 Oleg에게 감사합니다. Mariusz는 유일한 줄을 찾았습니다.

$responce = new stdClass(); 

$ reponce를 사용하기 전에 모든 것을 해결할 수 있고 이제 내 그리드가 훌륭합니다 !!!

내 친구들 감사합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top