1

I am applying client-side search to a jqGrid without the search dialog, but I need to perform the search with a custom search function or a more clever search operator, one of which will essentially do $.inArray([searchString],[searchField]).

My grid has datatype: 'json' and loadonce: 'true' and does not use multisearch. The relevant column I want to search has colModel: [ {name: 'ancestorIds', hidden: true } ] and it will contain an array of ids like [1,2,26,42]. Based on this answer, I am initializing the single field search from a click event outside the grid, something like this:

var selectedId = $('#selectedId').val();
var $grid = $('#grid');
var postdata = $grid.jqGrid('getGridParam','postData');
$.extend(postdata, {
    filters: '',
    searchField: 'ancestorIds',
    searchOper: 'cn',
    searchString: selectedId
}); 
$grid.jqGrid('setGridParam', { search: true, postData: postdata });
$grid.trigger("reloadGrid", [{page: 1}]);

This works fine, except if selectedId is 2, using searchOper: 'cn' will incorrectly return rows which include 26 or 42. My question is, how can I modify the search to only return rows where the selectedId is an actual value of the array?

EDIT:
Given several sample rows with the following values for ancestorIds, and a selectedId value of 2... [1,2,26,42]
[2]
[2,42]
[42]
[22]

...the code above is selecting every row, but I only want it to return the first three rows.

Community
  • 1
  • 1
aponzani
  • 438
  • 6
  • 10

1 Answers1

0

I am not full understand your example. If you want to have exact matching in the searching in 'ancestorIds' column you should just use 'eq' operation instead of 'cn'.

If you really need to implement very custom local searching method you can use the technique which I described in the answer.

If you need not so hardcore customization of local filtering you should describe your exact requirements more detailed.

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