1

i am trying to implement complex search functionality in jgrid. But i want to change the value that a user specified in a search box before user presses find button.

enter image description here

  1. Here you can see the values 17 20 35 36 37 53 54 and i want those values comma saperated so before i hit find i want to change the values in a text box so can anyone tell me how can i do that ?

  2. more over i want to know how can i customized the look of this search box forexample instead of id , is in i want some user friendly UI in which user can simple put the values and hit find , but i dont know how to change the look of this search box in inject our own look and make the search box non dragable

Hunt
  • 8,215
  • 28
  • 116
  • 256

3 Answers3

2

You can use split() to split it to an array on the spaces, and then .join() the array again, using a comma as the delimiter (default anyway).

$("input[type='text']").blur(function(){
  var value = this.value;
  this.value = value.split(' ').join(',');
});

DEMO: http://jsfiddle.net/mJaqm/

ahren
  • 16,803
  • 5
  • 50
  • 70
  • I don't want to make an answer basically replicating yours just because you didn't wrap it in a blur function. Can you put it in a blur function so I can upvote? – Ohgodwhy Sep 24 '12 at 05:50
  • @Ohgodwhy - Done, but you could have edited it, I wouldn't have minded ;-) – ahren Sep 24 '12 at 05:54
  • how would i know on which textbox i should use onblur there could be more textboxes and its jqgrid – Hunt Sep 24 '12 at 06:05
1

I recommend you to read the answer where I shown how implement even more complex changing of the user input as you need.

In case of Searching dialog you can use onSearch callback in the same way like one uses beforeSearch for the toolbar searching.

The main idea is that one can get the reference on the internal postData parameter of jqGrid with respect of getGridParam method. The filters property of the postData represent the filters serialized as the JSON string (see the documentation for details). So you can convert postData.filters to object (using $.parseJSON) modify if like you as need, convert back to JSON string (using JSON.stringify) and place the results back in postData.filters. If you do all the changes inside of onSearch or beforeSearch callback the modified filter will be used.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Hunt: I am currently at customer. I'll try to answer on the question shortly later when I'll come to hotel. – Oleg Sep 24 '12 at 14:40
0

You can add this to the onBlur event of the textbox, which fires when the cursor is taken away:

$("#theid").blur(function() {
    value = value.split(' ').join(',');
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252