1

When I used localhost:8080/SpringServiceJsonSample/rest/service/user/ on browser I return all data in json type, but when I used this url in jquery grid data is not loaded, I have also used debugger, but there is no error I got.

       jQuery("#grid").jqGrid({ 
          // url: '/Home/SampleGridData/',
           url: '/SpringServiceJsonSample/rest/service/user/',
           datatype: 'json',
           mtype: 'GET',
           contentType: "application/json" ,
           colNames: ['First Name',  'lastName'],
           colModel: [
             { name: 'firstName', index: 'name', width: 60, align: 'center', editable: true, editrules: { edithidden: false} },                

             { name: 'lastName', index: 'lastName', width: 200, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true, email: true} },               
           ],
           pager: jQuery('#pager'),
           rowNum: 10,
           rowList: [5, 10, 20, 50],
           sortorder: "asc",
           viewrecords: true,
           caption: 'JqGrid Sample',
           jsonReader: {
               repeatitems: true,
               id: "0",
               cell: "cell",
               rows : "details",
               page : "pageno"
               }
       });

});

my json value return like this::- [{"id":1,"firstName":"Pradeep","lastName":"Pradeep","email":null},{"id":2,"firstName":"Golu","lastName":"Golu","email":null}]

  • are you able to see request going to `localhost:8080/SpringServiceJsonSample/rest/service/user/` URL in browser's network section? are you getting 200 response code for it? – vijayP Oct 09 '15 at 10:08
  • it means that call is not at all getting invoked. Please check network section and see what ultimate URL is getting formed for `/SpringServiceJsonSample/rest/service/user/` – vijayP Oct 09 '15 at 10:18
  • You should append your question with exact example of the JSON data returned from the server. The information like "I return all data in json type" gives almost no information. The `jsonReader` should **corresponds** the format of the data. Moreover it's extremely important to know **which version of jqGrid you use**. – Oleg Oct 09 '15 at 10:33
  • @Oleg,dude ,jqGrid 4.1.1 – Naveen Maurya Oct 09 '15 at 10:46
  • @NaveenMaurya: It's really **retro version** of jqGrid published more as 3 years ago. I would recommend you upgrade to [free jqGrid](https://github.com/free-jqgrid/jqGrid) 4.9.2 or use it from CDN (see [the wiki](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs)). If you have to use old version of jqGrid then including of the exact JSON response is **really required** (2-3 rows of data would be enough) because the old version have no autodetection of JON format. – Oleg Oct 09 '15 at 10:54
  • @Oleg,dude my json value return like this -[{"userid":0,"firstName":"Pradeep","lastName":"Pradeep","email":null}, – Naveen Maurya Oct 09 '15 at 10:58
  • @NaveenMaurya: You should click on "edit" button below the text of your question and modify the text of the question by including new information. I asked you to post more as one rows of data. You use `id: "0"` and `repeatitems: true` at the same time and you use `rows : "details"` and `page : "pageno"` additionally. It's important to know id of rows. One need validate which settings of `jsonReader` corresponds your real data returned from the server. You don't use `loadonce: true` option. Do you implemented server side paging of data? How many rows of data you need to display in the grid? – Oleg Oct 09 '15 at 11:10
  • @Oleg,dude--Do you implemented server side paging of data?=no, How many rows of data you need to display in the grid?=12 – Naveen Maurya Oct 09 '15 at 11:24
  • Why `userid` have the same value for both rows? Is is unique id or not? Do you get the data from the database? Which id have the table? Is response start directly with `[`? In other words do you return **array of all items** as the server response? – Oleg Oct 09 '15 at 11:26
  • @Oleg sorry dude now json return type is--[{"id":1,"firstName":"Pradeep","lastName":"Pradeep","email":null},{"id":2,"firstName":"Golu","lastName":"Golu","email":null}] – Naveen Maurya Oct 09 '15 at 11:38
  • @Oleg,dude thank,thank ,thank u so much, i load this data after 2 days, beacuse of your help – Naveen Maurya Oct 09 '15 at 12:41

1 Answers1

1

You have to modify jsonReader to something like the following

jsonReader: {
    repeatitems: true,
    id: "userid",
    root: function (obj) { return obj; }
},
loadonce: true,
gridview: true,
autoencode: true,
height: "auto"

You should remove all index properties from colModel.

By the way the option contentType: "application/json" is not exist in jqGrid, but you can use ajaxGridOptions:{ contentType: "application/json" } instead if it's really required for your backend.

I would recommend you to update jqGrid which you use to the current version of free jqGrid. Additionally add loadError callback (see the answer) and to use Fiddler or Developer Tools of IE/Chrome to make trace of HTTP traffic between jqGrid and the server. Analyzing of HTTP traffic helps to understand communication between jqGrid and the server and to localize very quickly the origin on the problem.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798