1

We are upgrading both jQuery and jqGrid in a project and found a possible bug in jqGrid. The versions we are working with:

  • jQuery 1.4.1 upgraded to 1.7.1
  • jqGrid 3.8.2 upgraded to 4.2.0

We are using the colmodel's index parameter both for sorting and searching/filtering. The problem we have found appears when the index string contains a dot. E.g. "Customer.Name".

$('#grid').jqGrid({
  url: 'some/controller/action',
  datatype: 'json',
  colNames: ['Customer Name'],
  colModel: [{ name: 'CustomerName', index: 'Customer.Name' }]
});

$('#grid').jqGrid('filterGrid', '#filter',
{
  filterModel: [{ label: 'Customer Name', name: 'CustomerName', stype: 'text' }]
});

When the search is used the browser throws an exception as follows:

Syntax error, unrecognized expression: [name=Customer.Name]
http://localhost:8000/Scripts/jquery-1.7.1.js Line 4179

The exception is originating from row 465 in grid.addons.js which looks like this:

447: nm = this.index;
465: v = $("input[name="+nm+"]",self).val();

The code is inside an each operator and gets the value from the colModel/filterModel, so this is each element in that array.

After some research we found that in jQuery 1.5 the attribute selector requires quotes around the value, which the grid doesn't seem to use and thus failing when searching for the element.

Question is: Is there any workaround for this or should we post a bug to jqGrid and hope they fix it soon?

We have tried escaping the dot and surrounding the string with quotes, but nothing helps.

Anttu
  • 1,076
  • 1
  • 10
  • 21
  • You should include more code which shows *how* you use jqGrid. If you use `grid.addons.js` it means that you don't chosen the standard way. Probably you have an issue with `filterGrid` which are removed from jqGrid? There are other simple ways to send information from the external searching control to the server (see [here](http://stackoverflow.com/a/2928819/315935) for example). – Oleg Dec 28 '11 at 10:58
  • You're right...added some more code and tried to improved a few explanations. – Anttu Dec 28 '11 at 12:06

1 Answers1

1

The module grid.addons.js contains the methods like filterGrid which are not more supported. Instead of that you can just place the searching information directly in the postData (see here for details)

If you do want to use the code from grid.addons.js you have to maintain the code yourself. To solve your current problem you can use $.jgrid.jqID which escapes any meta-characters used inside of jQuery selectors. Try to replace

v = $("input[name="+nm+"]",self).val();

to

v = $("input[name=" + $.jgrid.jqID(nm) + "]", self).val();

I think it should solve the problem.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Yes, this did solve the problem in a cleaner way than what I did myself, by adding the missing quotes. However, in the [migration documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:upgrade_from_3.8_to_4.0.0) this is not very well explained and we did not interpret it as it's no longer maintained, but only not included by default. – Anttu Dec 28 '11 at 12:13
  • @Anttu: [Here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:upgrade_from_3.8_to_4.0.0#the_following_methods_are_no_more_supported) you can read that `filterGrid` method is **no more supported**. – Oleg Dec 28 '11 at 12:25