can't add data to jqGrid from php within json format

后端 未结 2 1249
情话喂你
情话喂你 2021-01-29 03:47

Hello StackOverFlow nation . I\'m trying to add information to jqGrid , which is retrieved from MySQL database. I\'ve two files => index.html and data.php (both in the same dire

2条回答
  •  一整个雨季
    2021-01-29 04:21

    Your response format is wrong. You can go to jqGrid Demos page where you will find a sample for PHP/MySQL after expanding Loading Data and then choosing JSON Data.

    The proper format of data should look like this:

    {
        "total": "1",
        "page": "1",
        "records": "2",
        "rows": [
            { "name": "Robert", "surname": "De Niro", "b_year": "1943", "film": "Once Upon A Time In America" },
            { "name": "Al", "surname": "Pacino", "b_year":"1971", "film": "Scent Of A Woman"}
        ]
    }
    

    Where:

    • total --> total count of pages
    • page --> current page number
    • records --> total count of records
    • rows --> the rows of data

    Also if you want rows to be objects, you need to disable repeatitems in jqGrid jsonReader options:

    $("#jqGrid_tb").jqGrid({
        ...
        jsonReader: { repeatitems: false }
    });
    

    It is also adviced for rows to have unique id for later reference.

提交回复
热议问题