JQgrid - escape ':' in searchoptions (value part)
Asked Answered
Q

2

5

How to set the values for filter is explained here link text. I have two requirements.
1. the default value needs to be empty. I expect, if defaultValue is not set, the filter is empty, but that is not happening in my case.
2. How to escape ':' in my value. The character ':' and ';' are used to seperate the index and values. But, in my value string it contains a ':' (eg: searchoptions:{value:"1:'Level: 1'"} , where Level: 1 is my first value). How to escape : in the value part. I tried \ , / etc.

thanks.

Edit: Item 1 may be solved if there is no other way. I may set an additional item ALL in the values, and use it default.

Quasijudicial answered 5/6, 2010 at 17:50 Comment(1)
I want only ask you whether my answer solve your problem or not?Mannino
M
6

You are right, it seems impossible to use any escape character to place ':' inside of value of searchoptions if you define it like a string:

searchoptions:{value:"1:'Level: 1'"}

There is another form of setting of value of searchoptions - object form, which is also described under http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config#colmodel_options. For example you can use following syntax

searchoptions:{value:{'1:': 'Level: 1;', ':2:;': 'Level: 2;'}}

It defines a select with the texts "Level: 1;" and "Level: 2;" displayed and the corresponding values "1:" and ":2:;". It works.

Mannino answered 11/6, 2010 at 13:30 Comment(5)
though I never tested the above solution, as I took another approach already, I may treat it as answered my qn.. thanks for ur help and time.Quasijudicial
FWIW, the official jqGrid blog states that it now has a workaround, considering only the first ':' as a separator of key:value options (within all the text contained between the ';' which separates options. This means now you can have any number of colons inside the string, and only the first will count as separator. More info here trirand.com/blog/?page_id=393/help/… . Additionaly, although useng an object instead of a string is valid, it has the disadvantage of losing the originial order of the list (it always orders it based on the index)Blennioid
@DiegoDD: The answer is 6 years old. searchoptions supports now two properties: separator, with default value ":" and delimiter, with default value ";". If one knows that the values can contains : then one can just specify separator with alternative symbol, which is not inside of the main values.Mannino
@Mannino : I am getting the same issue. My object will be like this {"1200":"10:00-12:00","900":"07:00-09:00"}. If I include :all option in the dropdown its not coming at the first option.. {"":"All","1200":"10:00-12:00","900":"07:00-09:00"}. I need that All option should come first. Could be please help me?Weissman
@Ranjith: I recommend you to use string as the value of searchoptions. You can use separator and delimiter properties if : or ; could be inside of the text or values. Additionally noFilterText is preferred for specifying "":"All" entry because the value will be used only in the filter toolbar, but not in the searching dialog. For example, searchoptions: { noFilterText: "All", separator: "@", value: "1200@10:00-12:00;900@07:00-09:00" }.Mannino
Q
0

I had the same issue and the only option was to use searchoptions object. However, I had to programmatically build the list so I couldn't use define the objects.

Therefore, I decided to use build the list as an JSON string and then parse it, as shown below:

  searchoptions: {
    value: $.parseJSON("{" + searchSelectFormat.join(",") + "}"),
    sopt: ['eq']
  }

where searchSelectFormat is in the format of

'"' + data + '":"' + data + '"';

'"' + item+ '":"' + item+ '"'

Questor answered 18/3, 2015 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.