You have not posted the full code that you are using. Therefore, I can only guess what you are doing.
If you have ajaxResponse
full data that you use to fill the grid, you can create a data grid. You can use data: ajaxResponse
along with gridview: true
. In the case when the entire grid will be created immediately:
var mydata = [ {id: 1, name: 'John', email: ' john@doe.co.uk '}, {id: 2, name: 'Michael', email: ' michael@example.com '} ]; $("#list").jqGrid({ datatype: 'local', data: mydata, colNames: ['Name', 'E-Mail'], colModel: [ {name: 'name', width: 100}, {name: 'email', width: 150} ], rowNum: 5, rowList: [5, 10, 20], pager: '#pager', gridview: true, rownumbers: true, sortname: 'name', sortorder: 'desc', caption: 'Just simple local grid', height: 'auto' });
(see demo here )
If you receive data from the server in JSON format, for example,
[ {"id": 1, "name": "John", "email": " john@doe.co.uk "}, {"id": 2, "name": "Michael", "email": " michael@e xample.com"} ]
you can set the url
parameter to the url of the server that provides the data and use
$("#list").jqGrid({ url: 'Nicolae2.json', datatype: 'json', jsonReader: { repeatitems: false, root: function (obj) { return obj; }, page: function () { return 1; }, total: function () { return 1; }, records: function (obj) { return obj.length; } }, loadonce: true, colNames: ['Name', 'E-Mail'], colModel: [ {name: 'name', width: 100}, {name: 'email', width: 150} ], rowNum: 5, rowList: [5, 10, 20], pager: '#pager', gridview: true, rownumbers: true, sortname: 'name', sortorder: 'asc', caption: 'Just simple local grid', height: 'auto' });
to populate the grid on Ajax directly from the server. The only limitation is that you have to provide correctly sorted data. So I changed sortorder: 'desc'
from the previous example to sortorder: 'asc'
. See the second demo here .