0

I'm having trouble with jqGrid not showing the "No records to view" message when there are no records to view. I've used jqGrid pretty extensively in my application, with variable row count selection, pagination, and filtering. When the tables are initially loaded, they correctly show the number of pages, and the "View 1-10 of 50" type rowcount message. If filters are then applied to the table, the data in the table is updated correctly (using a JSON data source generated by PHP), and the page and row count messages are updated correctly.

The only problem comes when filters are applied which return no rows at all - when this happens, the page count and row count messages remain set to their previous values.

I've checked the JSON I'm returning for an empty data set, and it matches the JSON from the jqGrid demo site when there is no data:

{"page":0,"total":0,"records":"0"}

I've posted a sample at http://www.analyticsseo.com/test. Any idea what I'm doing wrong?

Mark B
  • 4,768
  • 2
  • 25
  • 30
  • The demo uses jqGrid 3.8 (2010-09-21), jQuery 1.3.2 (2009-02-19) and jQuery UI 1.7.3. Moreover if you prepare a demo you should use non-minimized version of jqGrid - including of `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js` will be enough. – Oleg Jan 18 '12 at 16:08
  • @Oleg: Drupal 6 maxes out at jQuery v1.3.2. Sad but true I'm afraid. – Clive Jan 18 '12 at 16:10
  • My question was mostly about the jqGrid version. The version 3.8 is now really old. Moreover you could use `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js`. – Oleg Jan 18 '12 at 16:35
  • Thanks @Oleg - I'll give upgrading a try. A quick test shows that it's going to need a bit of work (unsurprising, as it's a major version upgrade), so if anyone has any ideas about why 3.8 isn't working, I'd still love to hear them. – Mark B Jan 18 '12 at 17:28

1 Answers1

1

I don't recommend you now so old version of jqGrid like 3.8. You main problem with server response

{"page":0,"total":0,"records":"0"}

can be fixed if the server would produce

{"page":0,"total":0,"records":"0","rows":[]}

instead. The bug like many other bugs are fixed in jqGrid now. There are many new features and performance improvements.

By the way your server part use wrong Content-Type header in the response with the JSON data. The correct Content-Type is application/json, but your server uses currently text/html; charset=utf-8 instead. You can use in Drupal 6, common.inc the statement drupal_set_header('Content-Type: application/json'); to fix the problem. After such change you will be able to use more recent version of jQuery.

In the answer you find references to the link which describes how you can upgrade jQuery to new version.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Awesome - that's sorted it. Thanks Oleg! I've changed the content type too, and will upgrade to jqGrid 4.x as soon as I get the chance to make the necessary changes to our json generation. – Mark B Jan 19 '12 at 09:12