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
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 pagespage
--> current page numberrecords
--> total count of recordsrows
--> the rows of dataAlso 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.
You should include
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
as additional option of jqGrid is you don't want to change format of input data. Moreover you should specify which values should assign jqGrid as id
attribute of the row. You can include additional id
property as additional property of every returned item or you can add key: true
property to the column (in colModel
) which contains unique values. For example if you can guarantied that the values from "name"
are already unique then you can include key: true
property in definition of "name"
column.
Additionally you can consider to use loadonce: true
option of jqGrid. In the case the full data of the grid will be loaded at once and the sorting, paging and searching (filtering) of data will be implemented by jqGrid on the client side without needs to implement some additional code on the server side. You should don't use the option in case of large number of rows (many hundred or many thousand rows) in the grid.