0

I am trying to display data in JqGrid from spring controller. Here is the JSON response from my spring controller {"rows":[{"firstName":"sharma","lastName":"sharma","id":2}],"page":"1","records":"1","total":"1"}

This is my jsp file:

<table id="grid"></table>
<div id="pager"></div>
<script type="text/javascript">
  $("#grid").jqGrid({
    url:'/url',
    colModel:[
      {name:'id', label: 'ID', formatter:'integer', width: 40},
      {name:'firstName', label: 'First name', width: 300},
      {name:'lastName', label: 'Last Name', width: 200}
    ],
    caption: "ReportingEmployees",
    pager : '#pager',
    height: 'auto'
  }).navGrid('#pager', {edit:false,add:false,del:false, search: false});
</script>

I have spent hours to figure out what is wrong, JSON looks valid also. Any help is much appreciated.

varun
  • 684
  • 1
  • 11
  • 30

1 Answers1

1

You need add the option

datatype: 'json'

UPDATED: The demo uses JSON data which you posted and your code where I added datatype: 'json'. It displays

enter image description here

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @varun: Look at the demo from **UPDATED** part of my answer. – Oleg Sep 16 '13 at 19:22
  • 1
    @varun: It's *the code which you posted*. You can just open the source of [the demo](http://www.ok-soft-gmbh.com/jqGrid/varun.htm) in context menu of the web browser. You can verify that [the JSON file](http://www.ok-soft-gmbh.com/jqGrid/varun.json) contains *your data* only. – Oleg Sep 16 '13 at 20:58
  • worked like a charm. There was a problem with jquery library version I was using. Thanks :) – varun Sep 18 '13 at 06:28