0

I have pulldown select box for filtering the jqgrid (not using the builtin navbar, and data is local). I'd like to grey out the ones that have no matches in the grid.

Is there a way to perform the query to just get the count without updating the ui rows so I can initialize/update the pulldown to enable only those with matches (or even better to supply the number of matches in the menu)

EDIT: To clarify I want to disable/greyout my filter menu items not the table row items

claya
  • 1,920
  • 1
  • 18
  • 32

1 Answers1

1

Internally jqGrid uses $.jgrid.from method to apply the filter to the data. What you want to implement it's probably not just getting the counts because you wrote:

I'd like to grey out the ones that have no matches in the grid.

Nevertheless all want you want is possible to implement. You will have to write some JavaScript code which uses $.jgrid.from($("#list")[0].p.data) for initialization. Then you have to construct the query using methods like contains, lessOrEquals, andNot, orNot and so on. Then you should apply the query with respect of var queryResults = query.select();. If you examine ids in the queryResults you can make gray all items which are not in the set.

I recommend you to read and to debug the addLocalData method of jqGrid and which contain all what you need. Moreover I recommend you to set breakpoint on the line and examine match and results variables. It this is not simple of cause, but if you need some individual solution you have to invest time in it.

UPDATED: I though more about the described problem. My recent answer with the demo demonstrate how you can solve your problem.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Great thanks I should clarify I want to grey out the dropdown menu items not the grid rows. so if my menu had apples, oranges, pears and my data had no oranges I would grey out that selection in the menu. So the user would see that type is not in the data set. I want to precalc which filters have no matches and disable the menu but not actual update the table rows appearance or rows shown. – claya Feb 26 '12 at 16:25
  • Is there any way to access to the tojLinq method to turn the filter option into a string that gets evaled for the match loop? – claya Feb 26 '12 at 17:38
  • @claya: No, you can't call `tojLinq` method from outside because it is defined as *local* function inside of *local* function `addLocalData`. Some other internal functions are do accessible (see [here](https://github.com/tonytomov/jqGrid/blob/v4.3.1/js/grid.base.js#L2530-2539)) but not `addLocalData`. If was the reason why I recommended you to examine the source code. So you have to use "cut & paste" method, copy and probably reduce the code which you need. You can just add filter bar with `filterToolbar` and debug what do `addLocalData` on applying a filter. Then you will see what you need. – Oleg Feb 26 '12 at 17:52
  • I was hoping to avoid cut&paste to be able to extend the plug in using the same functionality it already has coded. – claya Feb 26 '12 at 18:15
  • I have been debugging the method to see how the search is done. I have the filter criteria group object but don't see how I can execute it without the toJLinq function that's internal to addLocalData. So I have a extended method for jqgrid – claya Feb 26 '12 at 18:56
  • @claya: Copy & pasted of parts of `addLocalData` inclusive `tojLinq` is the only way which I see. One can't access **private** variables or **private** functions from outside. The simpler is your filter the more code of `tojLinq` you can remove. The code of `addLocalData` is only about 150 lines. What you will need depend on the filter complexity which you use will be about 50 lines of code. So you will be able to use without "cut & pasted" *the main code* of `$.jgrid.from` which is more as 400 lines. – Oleg Feb 26 '12 at 19:16
  • @claya: I think I fond simple solution of your problem. See **"UPDATED"** part of my answer. – Oleg Mar 22 '12 at 21:55