1

I have a jqgrid that is completely populated locally. I have a select element in the grid aswell. This is produced as shown below

{ name: 'sparkline', width: 200, editable: true, edittype: 'select', formatter: 'select', editoptions: { value: sparklinedropdownstring }, classes: "extracellpadding" }

the variable 'sparklinedropdownstring' is a string set out like the examples from http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules

"value:label;value1:label1;value2:label2;value4:label5;"....etc etc

Now whenever I use the search bar or sort it always sorts or searches based on the value and not the label, I was wondering if i could search via the label instead? there are a few times where the value doesn't have a lot in common with the label and the average user would search for a label rather then a programmer's value.

My search and sort toolbars are setout like so:

myGrid.jqGrid('navGrid', '#mypager', { edit: false, add: false, del: false, search: false });
myGrid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
Nick
  • 31
  • 4

1 Answers1

2

If you use formatter: "select" with "value:label;value1:label1;value2:label2;value4:label5;" then only value, value1, value2 etc. are in your input data. So jqGrid sort and search by the values.

If one need to sort by another value then one can use sorttype as function. It allows to replace the values from the grid to another values which will be used during sorting instead of original values in the column.

To search in column which have formatter: "select" one uses typically stype: "select" and searchoptions: {sopt: ["eq", "ne"], value: ":All;" + sparklinedropdownstring } (the searchoptions.value will be used the same as editoptions.value or formatoptions.value). As the result the user sees <select> with the same texts in the filter toolbar. So the user just have no other possibility as to choose some option by text. The additional item ":All;" in searchoptions.value are needed to allow the user to remove the filter in the column and to display all unfiltered items ("All" is the text and empty string "" is the value of the corresponding option of select).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for the reply, I was wondering if it was possible to have a search textbox (like the standard search) for the select column instead and look for the labels and not the values? Is it possible? Or maybe I should I change the way my select is formed? Would it be better to provide jqgrid an array instead? or is the string the best way? – Nick Sep 25 '14 at 01:41
  • @Nick: You are welcome! If you have large number of items in select I would recommend you better to use [select2](http://ivaynberg.github.io/select2/) control. It can combine the advantage of select and input box, See [the demo](http://www.ok-soft-gmbh.com/jqGrid/UsageFormetterSelect2.htm) created for [the answer](http://stackoverflow.com/a/19427444/315935). Alternatively you can just use simple textbox (like you asked) and replace label text to value inside of `beforeSearch` callback or `beforeRequest`. You need modify `filters` of `this.p.postData`. – Oleg Sep 25 '14 at 05:00
  • @Nick: [the demo](http://www.ok-soft-gmbh.com/jqGrid/MultiwordSearchingToolbar.htm) created for [the answer](http://stackoverflow.com/a/8953934/315935) do not what you need, but it shows how to make even much more complex modification of `postData.filters` inside of `beforeSearch` of `filterToolbar`. – Oleg Sep 25 '14 at 05:03