Here is my code from the Grid I currently have, (hope its ok) – Basically, my JSON is built automatically from PHP json_encode. It will provide a list of columns and then the data which will always fit in the same columns sequentially.
var url = "json/mainGrid.php"var source = { datatype: 'json', url: url, root: 'rowsinfo', cache: false, columns:[], beforeprocessing: function (data) { var columnsdata = new Array(); for (k in data.columnsinfo){ var col=[]; col.text = data.columnsinfo[k]["DISPLAYNAME"]; col.datafield = data.columnsinfo[k]["FIELDNAME"]; columnsdata.push(col); source.columns = columnsdata; } $("#jqxgrid").jqxGrid({columns : source.columns}); }, data: { startcolumn: 1, } };
Here is an example of my JSON Output (which could be wrong)
{"columnsinfo":{"FIELDNAME":"SEQUENCE","DISPLAYNAME":"Test #"}}{"rowsinfo":{"Test #":"1"}}